2

I'm trying to match the 2nd part of the slug with the category title to then place a 'current' class on the link.

Something like:

{% nav category in craft.categories.group('blogCategories') %}

    <a class="button button--outline-blue {% if craft.request.getSegment(2) == '{{ category.title }}' %}current{% endif %}" href="{{ category.url }}">{{ category.title }}</a>

{% endnav %}
4

You might do something like this, concerned that you want to set current on active category.

{% set categorySlug = craft.request.getLastSegment() %} 

{% nav category in craft.categories.group('blogCategories') %}
    {% set current = (category.slug == categorySlug) %}
    <a class="button button--outline-blue 
       {% if current %} current{% endif %}
       href="{{ category.url }}">
       {{ category.title }}
    </a>
{% endnav %}
  • Thanks. That's setting 'current' on all rather than just the one that matches the current slug. – sarah3585 Nov 2 '15 at 11:49
  • You may try now. – Dom Krulak Nov 2 '15 at 12:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.