Skip to content
Grav 2.0 is officially stable. Read the announcement →
General

Access the Taxonomy Filter in Twig

Started by Clemens HOLLEIS 7 years ago · 1 replies · 776 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 jean-louis67, 3 weeks ago
2 315 3 weeks ago
General · by Andy Miller, 4 weeks ago
0 312 4 weeks ago
General · by Veehem, 4 weeks ago
0 264 4 weeks ago
General · by milkboy, 4 weeks ago
0 270 4 weeks ago
General · by ian russell, 1 month ago
2 338 1 month ago