Skip to content
● Meet Grav Guard: keep every Grav site you run secure and up to date, all from one place. Free for up to 3 sites. Read more →

Relative path in twig

Started by Richard Hainsworth 9 years ago · 2 replies · 2133 views
9 years ago

The aim is to add into the navigation bar an arbitrary route or the parent page url, the route being defined in the parent content file, eg., inner.md. (I am also using onpage_menu: true)

I have a header field

YAML
up:
   route: /operation

And inside a twig file inner.htlm.twig

TWIG
{% set p_url = (header.up.route) ? header.up.route : page.parent.url %}

The problem is that the url being generated is <grav root>/operation, and not <grav root>/user/pages/operation

How do I access the base route for pages in twig?

9 years ago

Could it be that you are confusing paths and routes?
'<grav root>/user/pages/operationis a (partial filesystem) path and URL's in Grav do not containuser/pages`.

Perhaps you can use the value of filePathClean() and go from there.

👍 1
9 years ago

I admit, I don't completely understand the distinction between paths and routes, at least how to handle or generate them.

Thank you for pointing me to filePathClean(), which led me to other functions in Theme Variables. I had not thought of looking there for information on Twig functions.

Now I can go and experiment a bit to get something that I want.

Regards

Suggested topics

Topic Participants Replies Views Activity
General · by themetman, 23 hours ago
2 40 16 hours ago
General · by Hanns Mattes, 1 week ago
0 121 1 week ago
General · by Karmalakas, 1 week ago
2 185 1 week ago
General · by Hanns Mattes, 3 weeks ago
0 235 3 weeks ago
General · by Dima, 4 weeks ago
1 211 4 weeks ago