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.

Highlight current link in dynamic menu

February 22, 2014 8:37am

Subscribe [2]
  • #1 / Feb 22, 2014 8:37am

    Dotwebs

    13 posts

    Hi,

    My problem is that I have a navigation menu embedded on a page to display page content. The menu is dynamically created using the following:

    {exp:channel:entries channel="pages" status="open" category="134" orderby="priority" sort="asc" dynamic="no"}
    
           <li><a href="http://{title_permalink=site/about}">{title}</a></li>  
    
    {/exp:channel:entries}

    Normally I would use this to highlight the current:

    {if "{segment_1}" == {url_title} class="current"{/if}

    but I had to add ‘dymanic=“no”’ because having it enabled meant that only the current menu item showed when the page is rendered. So now finding the {url_title} doesn’t work.


    I’ve tried the solution on this page: http://ellislab.com/forums/viewthread/89951/P15 which is to:


    Find the current from the URL segment on the display page:

    {exp:channel:entries channel="pages" status="open" limit="1" url_title="{last_segment}"}

    And add the class using an ‘if’ statement based on the ‘current’ variable:

    <li {if "{embed:current}" == "{url_title}"} class="selected"{/if}><a href="http://{title_permalink=site/about}">{title}</a></li>


    but this isn’t working as it should, it adds the class to all menu items.

    Does anyone know of a way to do this?

    Thank you 😊

  • #2 / Feb 22, 2014 10:12am

    Boyink!

    5011 posts

    The dynamic property should not affect that conditional.

    Try:

    {if segment_1 == url_title} class="current"{/if}
  • #3 / Feb 22, 2014 11:05am

    Dotwebs

    13 posts

    Hi Boyink!

    Thanks for your reply.

    Your solution adds the class to the current but when I click any of the other links, the menu disappears!  I tried it with dynamic ‘no’ and ‘yes’ and the same happens with both.

    I don’t want to list out all the menu items because the client will want to add/remove items themselves via the admin.  Do you have any more suggestions?

     

  • #4 / Feb 22, 2014 11:11am

    Boyink!

    5011 posts

    Oh, sorry.  You need dynamic=“no” to keep all the menu items present. But it has no effect on segment variables or url_title variables working or not. You’re just telling the channel:entries tag tag to ignore the URL in deciding what to return.

  • #5 / Feb 24, 2014 8:24am

    Dotwebs

    13 posts

    Thanks again for the reply Boyink! That’s solved now 😊

    I had ‘dynamic=“no”’ in the page template as well as the embedded menu so once I removed it from the page, it stopped the menu from disappearing.

  • #6 / Feb 24, 2014 8:40am

    Boyink!

    5011 posts

    Cool. Do you grok what the dynamic=“no” does?

  • #7 / Feb 24, 2014 9:45am

    Dotwebs

    13 posts

    Yes, I understand that it’s used to prevent parameters that are passed from being used in results. But I did have to look up ‘grok’ 😊

  • #8 / Feb 24, 2014 9:52am

    Boyink!

    5011 posts

    Yes, I understand that it’s used to prevent parameters that are passed from being used in results.

    Um, yes but no..😉

    It tells the channel:entries tag from using the URL the template is loading at to know what entries to go pull from the database.

    I made this tutorial a while back for EE1 - the terminology has changed but the concepts have not:

    http://www.train-ee.com/courseware/free-tutorials/comments/dynamic-off-explained

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

ExpressionEngine News!

#eecms, #events, #releases