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

<pre><code>{% set categorySlug = craft.request.getLastSegment() %} 

{% nav category in craft.categories.group('blogCategories') %}
    {% set current = (category.slug == categorySlug) %}
    &lt;a class="button button--outline-blue 
       {% if current %} current{% endif %}
       href="{{ category.url }}"&gt;
       {{ category.title }}
    &lt;/a&gt;
{% endnav %}
</code></pre>

CC BY-SA 3.0
2015-11-02T11:49:08.147Z
Thanks. That's setting 'current' on all rather than just the one that matches the current slug.
sarah3585
CC BY-SA 3.0
2015-11-02T12:24:43.540Z
You may try now.
Dominik Krulak
CC BY-SA 3.0
2015-11-02T09:20:13.370Z
2015-11-02T12:24:14.863Z
2015-11-02T12:24:14.863Z
Dominik Krulak
<p>I'm trying to match the 2nd part of the slug with the category title to then place a 'current' class on the link.</p>

<p>Something like:</p>

<pre><code>{% nav category in craft.categories.group('blogCategories') %}

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

{% endnav %}
</code></pre>

<categories><getsegment>
getSegment matching category title
# getSegment matching category title

(Asked by: username_0 on 2015-11-02)

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') %}

    {{ category.title }}

{% endnav %}

**Tags:** categories, getsegment


---

## 1 answers

### Answer by username_1 on 2015-11-02. Score: 4 | Accepted answer

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) %}
    
       {{ category.title }}
    
{% endnav %}

> **Comments:**
> **username_0**: Thanks. That's setting 'current' on all rather than just the one that matches the current slug.  
> **username_1**: You may try now.  

---

