Jump to:

23372 Posts in 18175 Topics by 2865 members

General Questions

SilverStripe Forums » General Questions » Navigation

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: 770 Views
  • Mackodlak
    Avatar
    Community Member
    95 Posts

    Navigation Link to this post

    Hello, yet again.
    My new problem is this... in sitetree in menu(1) level I have 7 different pages, and then they span on.
    The thing is, when using navigation:

    <% control Menu(1) %>   
          <li><a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode"><span>$MenuTitle.XML</span></a></li>
    <% end_control %>

    I need it to show first 4 pages on one place and then 3 pages on another (so there will be 2 navbars)
    Which function fo I have to override to be able to do this?

    Thank you

  • stallain
    Avatar
    Community Member
    61 Posts

    Re: Navigation Link to this post

    Hi, I've already done this, but without creating any function.

    A first solution would be to have two different classes for your level(1) pages. Let's say, for instance the "Menu1" page type, and the "Menu2" page type. Then, for your first navigation bar, your code would be :

    <% control Menu(1) %>
    <% if ClassName = Menu1 %>
    <a href=$Link>$Title</a>
    <% else %>
    <% end_if %>
    <% end_control %>


    ... and same thing with <% if ClassName = Menu2 %> for your second nav bar.

    A second solution would be to create a tickable box in the cms that the user checks if he wants the page to show up in the first nav bar. Let's call it "ShowInMenuOne". Your code becomes :

    <% control Menu(1) %>
    <% if ShowInMenuOne %>
    <a href=$Link>$Title</a>
    <% else %>
    <% end_if %>
    <% end_control %>


    for the first nav bar and

    <% control Menu(1) %>
    <% if ShowInMenuOne %>
    <% else %>
    <a href=$Link>$Title</a>
    <% end_if %>
    <% end_control %>


    For the second nav bar.

    I'm sure it's not the most intelligent way to handle your problem, but it works !

  • Mackodlak
    Avatar
    Community Member
    95 Posts

    Re: Navigation Link to this post

    Hey,
    thanks for the answer, it helped.
    It does work, it just doesn't feel right, but ok, I guess whatever gets the job done.

    Cya mate!

  • zenmonkey
    Avatar
    Community Member
    527 Posts

    Re: Navigation Link to this post

    Similar to stallain's solution, but I'd add a field to the Page class for the two menu's that way you can filter on that field instead of class name, this will allow you to set it on any page type. Slightly more flexible because you're not reliant on having specific page-typesbuild your nav

    770 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.