statamic / v2-hub

Statamic 2 - Feature Requests and Bug Reports
https://statamic.com
95 stars 5 forks source link

Using is_current on taxonomy listing #2020

Open wesort opened 6 years ago

wesort commented 6 years ago

I have a Taxonomy called "tags". In the template I have a listing of those tags and I'd like to add a CSS class when visitors are on that tag's page. I thought I'd be able to use if_current like on the nav tag, but I found I had to use {{ if slug == last_segment }} instead.
Feature request for using if_current on taxonomies.

Also, using {{ count }} was rendering the sequence numbers of the tags listed, not the number of times that term has been used on an entry. This was resolved by scoping which feels unnecessary.
Bug?

<ul>
    {{ taxonomy:tags scope="tags" }}
      <li>
        <a href="{{ url }}" class="{{ if slug == last_segment }}current{{ endif }}">{{ title }}</a>
        <sup>{{ tags:count }}</sup>
      </li>
  {{ /taxonomy:tags }}
</ul>
jasonvarga commented 6 years ago

count is the loop interation, results is the number of times the taxonomy term has been used. They are both documented on the tag's docs page. https://docs.statamic.com/tags/taxonomy#variables

wesort commented 6 years ago

My apologies on missing results. I should have RTFM.

if_current would still be useful on taxonomies though right? Not that my workaround is that lengthy, but if_current would be a logical condition.