How to get active taxonomy

Hi,

I’m new with Grav and i’m liking it so far, it is extremely flexible.
I’m trying some things and I’m using the taxonomy list to display the blog categories. I am trying to get the current taxonomy so I could give the

  • an active class. Any ideas how best to do this?

    Thanks in advance.

  • You can get the current page’s taxonomy with page.taxonomy() this returns a nested array of taxonomy types (try doing {{ dump (page.taxonomy()) } in your Twig template with debugger on)

    It will contain all taxonomy types so if you want to see the current category it would be something like:

    {% set page_category = page.taxonomy().category|first %}
    

    This will get the first category (you probably only have one), then you can compare that to the list you are outputting and if they are equal, add the active class.

    Brilliant!

    {{ page.taxonomy().category|first }} works just fine, however I am unable to use {{ dump (page.taxonomy()) }}
    in the same page even though debugger is on, why is that, it returns nothing?

    Now this works on blog items which has taxonomy set, how would I get the selected taxonomy on the blog item list where the url is like category:news. On this page there is no taxonomy set so I can’t use the page.taxonomy(). What do you suggest?

    Thanks in advance.

    Oh, the debug bar wasn’t loading :slight_smile:

    Still trying to figure out how to get the current taxonomy from the querystring

    The solution was pretty straight forward:

    {% set activeTax = uri.param(‘category’) %}

    PS: Sorry for spamming the forum haha

    No problem. You all sortded?

    Yes! It is working, thanks :slight_smile: