Problems, need help? Have a tip or advice? Post it here.
3 posts Page 1 of 1
Hi

I've used the code below for a navigation structure. (found this example on the forum)
Now I would like to add an 'active' class to the active page.

I've tried something with code in bold, but it's not working, every link is getting active.

Thanks for looking into this!

Code: Select all
[b]<cms:set current_page = k_page_title />[/b]

    <cms:nested_pages masterpage='index.php' extended_info='1' >
        <cms:if k_level_start >
          <cms:if k_level='0'>
            <ul class="sidebar-nav">
          <cms:else />
                <ul id="vehicles-dropdown">           
            </cms:if>
          </cms:if>
        <cms:if k_element_start >
            <cms:if k_immediate_children ='0'>
                <li><a href="<cms:show k_menu_link />" [b]class="<cms:if current_page = k_page_title>active</cms:if>"[/b]><cms:show k_nestedpage_title /></a>
            <cms:else />
                <li><a href="#" id="vehicles-button"><cms:show k_nestedpage_title /></a></li>
            </cms:if>
        </cms:if>
        <cms:if k_element_end ></li></cms:if>
        <cms:if k_level_end ></ul></cms:if>
    </cms:nested_pages>
Hi Sam,

Perhaps you should use the following
Code: Select all
<cms:set current_page = k_page_name />
..
class="<cms:if current_page = k_nestedpage_name>active</cms:if>"

Anyway, you actually don't need to check for this as cms:nested_pages already makes this info available- please try the following:
Code: Select all
class="<cms:if k_is_active> active</cms:if><cms:if k_is_current> current</cms:if>"

In the code above, 'k_is_current' is set only on the precise menu-item that is being visited while 'k_is_active' is set on it as well as all its ancestors (helpful if you want to show an active trail).

Please see http://docs.couchcms.com/tags-reference ... pages.html for full details of all the variables that get available.

Hope it helps.
Super!
Thanks for the quick help.
3 posts Page 1 of 1