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 save menu state?

November 22, 2012 5:35am

Subscribe [2]
  • #1 / Nov 22, 2012 5:35am

    Hi! I have vertical navigation menu on my site pages. And the distinct menu items have subitems that expandes when I click on the parent item. So I have some state of menu where some items are expanded and some are collapsed. But if I go to another site page the state of menu is changes according to page template. How can I do my menu save state while I move to another page?

    My template:      When click on menu item:        When go to another page:

        item1 >            item1 >                                          item1 >
        item2 >                subitem1                                   item2 >
        item3 >                subitem2                                   item3 >
        item4 >                subitem3                                   item4 >
                                  item2 >
                                  item3 >
                                  item4 >

    P.S.: Menu consists of html/css and jquery for expanding and collapsing items.

  • #2 / Nov 22, 2012 9:46am

    Boyink!

    5011 posts

    Probably through some EE conditionals that look at the current URL using segment variables and apply a CSS class:

    {if segment_2=="news"} class="active"{/if}

    The exact code will depend on what your front-end code expects and is capable of.

  • #3 / Nov 22, 2012 11:24am

    I think this solution is not for my situation. This issue works fine if the state of menu depends on the URL. But in my case it depends on user action.

    P.S.: Boyink! May be I’ve understood you not correctly or you me.

  • #4 / Nov 22, 2012 12:42pm

    Boyink!

    5011 posts

    No I think I have you. If the menu doesn’t look at the URL then I don’t think this is an EE question as it all happens in the browser after EE has finished.

  • #5 / Nov 22, 2012 1:37pm

    Yes, you are right.
    So, when user click on parent menu item I change the class value of this item (html tag <li> in my case). And then depending on class value I show or hide menu subitems by using jquery “.show” and “.hide”. But if user go to another site page, he see the page witn all hidden menu subitems, because this view is in my EE template.

    So, as variant I can to save menu state in cookies after it changes.  But I assumed there is a special mechanism in EE for similar cases as mine. What could you advise to me? What decision?

  • #6 / Nov 23, 2012 9:54am

    Boyink!

    5011 posts

    EE doesn’t have anything built in to do what you are looking for, since EE doesn’t dicate front-end coding approaches.

    Personally I dislike menus that hide nav options so I tend to not need a solution in this area, but the few times I have it could be done by looking at the URL.

    All that to say - I got nothing..😉

  • #7 / Nov 23, 2012 1:22pm

    ok, anyway thank you very much!!!

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

ExpressionEngine News!

#eecms, #events, #releases