Dymanic 'active' class using nav tag looping through a structure My question is related to this page... How can I add a dynamic &quot;active&quot; CSS class to the navigation on any given page?

Thank you in advance my code is the following:

&lt;ul id="slide-in"&gt; 
    {% nav menu in craft.entries.section('mainMenu') %}
        &lt;li class="{{ menu.id == entry.id ? 'active' }}"&gt;
            &lt;a href="{{ menu.menuLink[0].url }}"&gt;{{ menu.title }}&lt;/a&gt;
        &lt;/li&gt;
    {% endnav %}
&lt;/ul&gt;


I am using Ben's code from this page but I am struggling to get this method working. I was wondering if someone could help me get to the bottom of this. I assume menu.id does not match entry.id and therefore the class is not added but how can I check the two id's are matching?
My recommendation is to match the slugs as opposed to the ids as this is much easier to debug.

&lt;ul id="slide-in"&gt; 
    {% nav menu in craft.entries.section('mainMenu') %}
        DEBUG: Entry.slug={{ entry.slug }} 
        DEBUG: menu.slug={{ menu.slug }} 
        &lt;li class="{{ menu.slug == entry.slug ? 'active' }}"&gt;
            &lt;a href="{{ menu.menuLink[0].url }}"&gt;{{ menu.title }}&lt;/a&gt;
        &lt;/li&gt;
    {% endnav %}
&lt;/ul&gt;


Then obviously remove the debug lines once everything is working as intended :)