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.

Determine and show the current STATIC PAGE location in navigation

December 17, 2007 12:06am

Subscribe [3]
  • #1 / Dec 17, 2007 12:06am

    demetrius

    2 posts

    Hello, everybody!

    I’ve got a great problem - to apply a class to the actual current menu item. I know how to do it with entries, but what about static pages (built with Pages Module)?

    I tried to use

    <li {if page_uri != 'event.htm'}class="here"{/if}><a href="/event.htm">Event</a></li>

    (where event.htm is the name is my static page)
    but class=“here” applies to every item…

    What I am doing wrong? It’s very important for me, I’ll be very grateful for the solution.

  • #2 / Dec 17, 2007 11:46am

    scottdevries

    103 posts

    I think you’ll want to use ‘==’ instead of ‘!=’. That should apply the class only if event.htm is the current page.

  • #3 / Dec 18, 2007 11:25am

    Bluebloc

    111 posts

    Hi,

    I’ve been having a similar problem when trying to css highlight current links to static pages in a weblog.

    When using:

    <li {if page_uri == '/about-the-ipi/'}class="current"{/if}><a href="/about-the-ipi/">About the IPI</a></li>


    nothing happens.

    When I replace “==” with “!=” in the if statement it prints the class=“current” regardless of uri.

    I’ve also tried using:

    <div class="box">
    <h5 class="box-h">About Us</h5>
    <ul class="navlist">
    {exp:weblog:entries weblog="about-us" show_pages="only" rdf="off" dynamic="off" disable="trackbacks"}
    <li {if page_uri == 'page_uri'}class="current"{/if}><a href="http://{page_uri}">{title}</a></li>
    {/exp:weblog:entries}
    </ul>
     </div>    <!-- # box -->

    but to no avail. Am I missing something straightforward?
    Any help greatly appreciated.

    Thanks

  • #4 / Dec 18, 2007 6:08pm

    scottdevries

    103 posts

    Instead of using page_uri, have you tried using segment variables?

  • #5 / Dec 18, 2007 10:57pm

    Bluebloc

    111 posts

    Yes, i have tried this, though i have run into problems with uri’s such as /about-us/ where the “about-us” segment comes directly after http://www.domain.com.

    An example is http://www.domain.com/about-us/

    Does EE recognise this 2nd half of the URL as “segment 2”, “segment 3” or “segment 4”?

    Is this where i’m making my error?

    Thanks

  • #6 / Dec 18, 2007 10:59pm

    Lisa Wess

    20502 posts

    Does EE recognise this 2nd half of the URL as “segment 2”, “segment 3” or “segment 4”?

    Segment 1. See URL Segment Variables =)

  • #7 / Dec 20, 2007 12:18pm

    Bluebloc

    111 posts

    Hi,

    Thanks for the advice above. However I’m still trying to get things working properly.

    The code below is contained in an embedded template with a list of links. When using “segment_1 !=” the “current” class is displayed regardless what segment_1 is. Nothing displays when using “segment_1 ==”

    <li {if segment_1 != '/about-the-ipi/'}class="current"{if:else}class="red"{/if}><a href="/about-the-ipi/">About the IPI</a></li>
    <li {if segment_1 == '/ipi-council/'}class="current"{if:else}class="red"{/if}><a href="/ipi-council/">IPI Council</a></li>
    <li {if segment_1 != '/articles-of-association/'}class="current"{if:else}class="red"{/if}><a href="/articles-of-association/">Articles of Association</a></li>

    Any ideas where i’m missing something?

    Thanks

  • #8 / Dec 20, 2007 2:15pm

    Lisa Wess

    20502 posts

    Don’t use the slashes.

    For instance:

    {if segment_1 != "about_the_ipi"}
  • #9 / Dec 20, 2007 2:48pm

    Bluebloc

    111 posts

    Hi Lisa

    That works. But weirdly it works in reverse!

    The list item code is:

    <li {if segment_1 != 'about-the-ipi'}class="current"{if:else}class="red"{/if}><a href="/about-the-ipi/">About the IPI</a></li>

    etc.

    And the resulting html when at the /about-the-ipi/ page is:

    <li class="red"><a href="/about-the-ipi/">About the IPI</a></li>

    Obviously the quick fix is to switch the classes. But i thought class=“current” should have been printed in the above code.

    Thanks

  • #10 / Dec 20, 2007 3:08pm

    Lisa Wess

    20502 posts

    In your code, you’re saying this:

    If segment 1 is not equal to “about-the-ipi” - then show class=“current” / ({If:else}) if something other than that happens, then class=“red”.

    I’m not sure what the actual URL here is, so I’ll reserve judgement on expectations. =)

  • #11 / Dec 20, 2007 3:13pm

    Bluebloc

    111 posts

    ah! sorted now Lisa. Thanks again

  • #12 / Dec 20, 2007 3:19pm

    Lisa Wess

    20502 posts

    Glad I was able to help - what was it in the end?  It is always great to confirm that for future viewers with similar questions. =)

  • #13 / Dec 20, 2007 3:27pm

    Bluebloc

    111 posts

    The problem was my post xmas lunch brain

    What i wanted was segment 1 equal to “about-the-ipi” - then show class=“current” rather than segment 1 is not equal to “about-the-ipi” - then show class=“current”

    Hence: == not != :red:

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

ExpressionEngine News!

#eecms, #events, #releases