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.

class="active" - Main Navigation - Trying to figure it out

April 02, 2008 5:53pm

Subscribe [3]
  • #1 / Apr 02, 2008 5:53pm

    wurdz

    14 posts

    So, I’m deep in the middle of my first EE site and have a few bumps, scrapes, and bruises, but no contusions! 😊

    I’m trying to figure out how to incorporate an “active class” for the main navigation of my site.

    I’ve successfully used segment_1 tag in this fashion:

    <li {if segment_1=="visitors"}class="active"{/if}>

    But I’d like a different way if possible, because it only matches up to the url the way it’s cased exactly. For example, http://www.mydomain.com/weblog works, but http://www.mydomain.com/WEBlog doesn’t work.

    I’ve tried this option:

    http://ellislab.com/blog/entry/behind_the_curtain_part_one/

    and

    {embed="inc/.head" page_name="Visitors" loc="Visitors"}

    was put in the index file of the weblog

    and

    <li {if '{embed:loc}' == 'visitors'}class="active"{/if}>

    was inserted in the <li>.

    But I can’t get it to work.  😏

    Yes, I’ve tried capitalized “Visitors” and lowercase “visitors” which made no difference.
    Yes, the CSS code and HTML works with static content and validates 100% as XHTML strict.

    Any thoughts as to why this option won’t work?

  • #2 / Apr 02, 2008 10:33pm

    Arun S.

    792 posts

    Try this:

    <li {if embed:loc == "Visitors"}class="active"{/if}>

    You don’t need the braces around embed:loc.  Also, it is case sensitive.

    The above should work.

  • #3 / Apr 02, 2008 11:33pm

    wurdz

    14 posts

    Thanks, VisualBinary.

    Hmmm. It didn’t work. I’m stumped why it wouldn’t.

    I’ve tried it 30 times now with different combinations of code.

  • #4 / Apr 03, 2008 12:05am

    Arun S.

    792 posts

    Thanks, VisualBinary.

    Hmmm. It didn’t work. I’m stumped why it wouldn’t.

    I’ve tried it 30 times now with different combinations of code.

    Really?  I tested it and it worked for me just fine.  I suspect something else is up then.  Do you have a link to the problem page?

  • #5 / Apr 03, 2008 9:31am

    andculture

    24 posts

    Wurdz, if you’re trying to style something at the page level (like an active element in a main navigation), why try to apply a body class to the page? You could use the short name of your weblog as a body class and then using CSS style your navigation item appropriately. You could does this as well by using URL segments, looking for either a certain template name or a weblog short name once again.

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

ExpressionEngine News!

#eecms, #events, #releases