Skip to content
Grav 2.1 is out: every page speaks Markdown. Read the announcement →

Relative path in twig

Started by Richard Hainsworth 8 years ago · 2 replies · 1961 views
8 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?

8 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
8 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 jeremycherfas, 1 week ago
4 181 2 days ago
General · by lynbor, 6 days ago
2 124 3 days ago
General · by Old Man Umby, 1 week ago
1 100 1 week ago
General · by Sebastian, 1 week ago
1 124 1 week ago
General · by Andy Miller, 3 weeks ago
0 248 3 weeks ago