Setting the Active Nav Item in Tag Navigation

Problem

You’re using tags to categorize your posts and have navigation for those tags/categories where you want to set the active state of the tag you’re currently viewing based on the URL.

Solution

{# getSegment(3) and blog/category examples show synching up current tag's name with URL #}

{% for tag in craft.tags.set('blog').find() %}
<li{% if craft.request.getSegment(3) is defined %}{% if craft.request.getSegment(3) == tag.name %} class="here"{% endif %}{% endif %}><a href="{{ url('blog') }}/category/{{ tag.name | url_encode }}">{{ tag }}</a></li>
{% endfor %}