Muut
1
Is it possible to get URI segment data from Grav? E.g. if I have a page on a site like this:
www.mysite.com/folder/page/item/
I want to get segment data for that page - so segment 1 == folder, segment 2 == page etc. Then I can do something like:
if segment2 exists then show sub nav
Etc… thanks
Muut
2
Hi, in Twig you can reference grav.uri.paths
and that will return an array of the segments found in the URL
So you can check for example {{dump("folder" in grav.uri.paths)}}
Muut
3
Hi, yeah ok so that gives me this:
array:2 [
0 => "test"
1 => "test-child"
]
If i’m at /test/test-child… but how can I use that in a twig variable? E.g:
{% if segment_0 == "test" %} foo
Muut
4
Ok so I go this working:
{% if grav.uri.paths.0 == "test" %} do something {% endif %}
But this doesn’t work - any ideas?
{% if grav.uri.paths.count() > 0 %} this has a child {% endif %}
Muut
5
And got it…
{% if grav.uri.paths.0 %} do something {% endif %}