ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

How to get EE to output a CSS ID or Class for active menu items?

April 26, 2008 2:36pm

Subscribe [3]
  • #1 / Apr 26, 2008 2:36pm

    StR@ng3r

    12 posts

    I am creating a menu that I’m going to ebmed into my templates. How would I be able to show my users which menu item is the one they are currently on?

    I’d like to do it semilar to how it’s done here on the site. The active menu item gets it’s own class (class=“current”).

    Maybe someone knows how that can be done. Thank you!

    <ul id="supportMenu">
                    <li><a href="http://expressionengine.com/docs/">User Guide</a></li>
                    <li class="current"><a href="http://expressionengine.com/knowledge_base/">Knowledge Base</a></li>
    
                    <li ><a href="http://expressionengine.com/wiki/">Wiki</a></li>
                    <li><a href="http://ellislab.com/forums/">Forum</a></li>
                    <li ><a href="http://expressionengine.com/developers/">Developers</a></li>
                    <li ><a href="http://expressionengine.com/bug_tracker/">Bug Tracker</a></li>
                </ul>
  • #2 / Apr 27, 2008 4:11am

    Greg Aker

    6022 posts

    Read up on URL Segment Variables


    EG:

    <li{if segment_1 != 'about' && segment_1 != 'wiki' && segment_1 != 'contact'} class="current"{/if}><a href="http://{path=" title="home">home</a></li>
    <li{if segment_1 == 'about'} class="current"{/if}><a href="http://{path=" title="about">about</a></li>
    <li{if segment_1 == 'wiki'} class="current"{/if}><a href="http://{path=" title="wiki">wiki</a></li>
    <li{if segment_1 == 'contact'} class="current"{/if}><a href="http://{path=" title="contact">contact</a></li>

    for me, I always like to check that the ‘home’ page doesn’t equal to everything else, so that if you go to example.com OR example.com/index.php/home, it will be the same.  There could be other ways for it, but that works for me.  Read up on all the different conditionals, and you’ll be cool.

    Regards,

    -greg

  • #3 / Apr 27, 2008 10:09am

    StR@ng3r

    12 posts

    Thank you very much!

  • #4 / Apr 27, 2008 11:05am

    e-man

    1816 posts

    Also have a look at this article by Derek which uses embedded templates.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases