Skip to content
● Grav 2.2 is out: 2x faster cold starts and 96% less memory on big sites. Read the announcement →

Access the Taxonomy Filter in Twig

Started by Clemens HOLLEIS 7 years ago · 1 replies · 835 views
7 years ago

Hi,
I'm wondering how can i access the taxonomy filter passed via the url in my TWIG-Template.

Simple example
i filter a events for the tag concert and want to print the used filter word on my page...
url: www.mydomain.com/eventslist/tag:concert

how can i print the "concert" tag filter in my twig template?
{{ page.url }} returns only the url without the tag section

br Clemens

7 years ago

@clemens, Try uri instead of url

{{ var_dump(uri.params) }} returns: '/tag:concert'

{{ var_dump(uri.extractParams(uri, ':')) }} returns:

JS
array (size=2)
  0 => string 'http://localhost' (length=16)
  1 => 
    array (size=1)
      'tag' => string 'concert' (length=7)

{{ var_dump(uri.extractParams(uri, ':')[1]['tag']) }} returns: 'concert'

For more functions available for Uri, see Class: \Grav\Common\Uri

👍 1

Suggested topics

Topic Participants Replies Views Activity
General · by Andy Miller, 7 days ago
0 112 7 days ago
General · by lynbor, 1 month ago
3 439 2 weeks ago
General · by lynbor, 3 weeks ago
7 562 2 weeks ago
General · by Harry, 2 weeks ago
0 161 2 weeks ago
General · by Old Man Umby, 1 month ago
2 309 3 weeks ago