How do I conditionally set active state in category navigation? Here is the code I am trying to use to set an active state for category navigation:

    {% for category in categories %}
        &lt;li {% if craft.request.segment(2) == "{{ category.slug }}" %}class="active"{% endif %}&gt;&lt;a href="{{ category.url }}"&gt;{{ category.title }}&lt;/a&gt;&lt;/li&gt;
    {% endfor %}﻿


It seems that the conditional can't check against the category.slug output. Is this the case? What would be a better approach?

Any help is appreciated.
You don't need the quotes or braces in twig tags to reference variables.

{% for category in categories %}
    &lt;li {% if craft.request.segment(2) == category.slug %}class="active"{% endif %}&gt;&lt;a href="{{ category.url }}"&gt;{{ category.title }}&lt;/a&gt;&lt;/li&gt;
{% endfor %}﻿


You could also use ternary operators:

{% for category in categories %}
    &lt;li {{ craft.request.segment(2) == category.slug ? 'class="active"' : "" }}&gt;&lt;a href="{{ category.url }}"&gt;{{ category.title }}&lt;/a&gt;&lt;/li&gt;
{% endfor %}﻿