Jump to:

3432 Posts in 1025 Topics by 865 members

Template Questions

SilverStripe Forums » Template Questions » Issue with menu levels

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

Page: 1
Go to End
Author Topic: 1932 Views
  • fishe
    Avatar
    Community Member
    42 Posts

    Issue with menu levels Link to this post

    Hey

    I have the following code in a Includes/Navigation.ss file:

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

          <% if Menu(2) %>
          <ul id="Menu2">
              <% control Menu(2) %>
                <li><a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode"><span>$MenuTitle.XML</span></a></li>

             <% end_control %>
             </ul>
          <% end_if %>

       <% end_control %>
    </ul>

    And the Page.ss simply does a: <% include Navigation %>

    My problem is that the list output from Navigation.ss is not including the second level (i.e. Menu(2) ). However, there is a menu(2) existing for one of the top level menu items, and this is correctly outputted on that item's page (e.g. when I click that page - as in Layout/Page.ss there is output code similar to above to show the Menu(2) items and breadcrumbs etc.)

    So basically, it will find/output menu(2) only when the page that actually has a menu(2) component is "active" - and not just on the homepage for example.

    What could be going wrong here?

    Thanks

  • Willr
    Avatar
    Forum Moderator
    5483 Posts

    Re: Issue with menu levels Link to this post

    Menu(2) returns the menu for the current page, not the page within the loop.

    Instead of doing the <% control Menu(2) %> inside the <% control Menu(1) %> you need to do <% control Children %> instead. To make sure the 2nd level is only shown when you are on that parent page or a child page of that you can wrap the <% control Children %> in a <% if LinkOrSection = section %> which will return true if you are on that page or a child of that page

  • fishe
    Avatar
    Community Member
    42 Posts

    Re: Issue with menu levels Link to this post

    Thanks for the help will!

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