How can I add a dynamic "active" CSS class to the navigation on any given page? Just wondering how people approach setting a class of current in their navigation. Is there anything in Craft or Twig where you can set a conditional to check if a page is the current page. Or do you just need to set classes/ids on the body tag based on the segment?

Any ideas appreciated, Gareth
Tip: To keep it short and reusable I would recommend that you wrap your preferred "check-method" in a Twig macro, I like Anna's version the most:

_macros.html:

{% macro is_active(segment) %}{% if craft.request.firstSegment == segment %}active{% endif %}{% endmacro %}


layout.html:

{% import "_macros.html" as macros %}

&lt;a href="{{ url('news') }}" class="{{ macros.is_active('news') }}"&gt;News&lt;/a&gt;
&lt;a href="{{ url('blog') }}" class="{{ macros.is_active('blog') }}"&gt;Blog&lt;/a&gt;