Jump to:

23550 Posts in 19336 Topics by 2890 members

General Questions

SilverStripe Forums » General Questions » Best way to hide some menu item

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 784 Views
  • Possibles
    Avatar
    Community Member
    16 Posts

    Best way to hide some menu item Link to this post

    Hello

    I have this scenario where a website has 2 main section (A and B) those are not part of the menu they are hardcoded (maybe they should be)

    Their main menu is common exept for 2 or 3 items that changes or dissapear . So my question is is there a best way to dynamicaly hide some menu item depending on a global variable or something else

    If someone could give me a link to some doc or tutorial I could use for that it would be greatly apr├ęciated

    Thanks

  • Willr
    Avatar
    Forum Moderator
    5511 Posts

    Re: Best way to hide some menu item Link to this post

    You can hide given pages in the CMS by unticking the 'Show In Menus' checkbox under the behaviour tab.

  • Possibles
    Avatar
    Community Member
    16 Posts

    Re: Best way to hide some menu item Link to this post

    Hello Willr.

    I just saw your answer.

    I can not do it like that, because the visiblity of my menu item depends on wich section A or B I'm. Those sections are not a menu level in my scenario they are defining a global variable to select the visible and not visible menu item.

    Thanks

  • JonoM
    Avatar
    Community Member
    103 Posts

    Re: Best way to hide some menu item Link to this post

    You could define something like this on your Page class

    public static $db = array(
       "HideFromMenuA" => "Boolean",
       "HideFromMenuB" => "Boolean"
    );

    Then for your main menus something like this for Menu A

    <ul>
       <% control Menu(1) %>
          <% if HideFromMenuA == 0 %>
             <li class="$LinkingMode"><a href="$Link" title="Go to the &quot;{$Title.HTMLATT}&quot; page">$MenuTitle</a></li>
          <% end_if %>
       <% end_control %>
    </ul>

    And this for Menu B

    <ul>
       <% control Menu(1) %>
          <% if HideFromMenuB == 0 %>
             <li class="$LinkingMode"><a href="$Link" title="Go to the &quot;{$Title.HTMLATT}&quot; page">$MenuTitle</a></li>
          <% end_if %>
       <% end_control %>
    </ul>

  • Possibles
    Avatar
    Community Member
    16 Posts

    Re: Best way to hide some menu item Link to this post

    Thanks a lot

    It looks great and simple.

    The only problem I have now is how to trigger those bollean values with my 2 hardcoded buttons

    Thanks

  • JonoM
    Avatar
    Community Member
    103 Posts

    Re: Best way to hide some menu item Link to this post

    What do you mean by hardcoded buttons? Can you post your code?

  • Possibles
    Avatar
    Community Member
    16 Posts

    Re: Best way to hide some menu item Link to this post

    Hello

    These are two hardcoded button <a href> buttons in the Page.ss template
    But I guess it is not the good solution as they could never relate to the bollean variables.

    I will first try to set up your code and see how it goes from there

    Thanks for your help

    T

    784 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.