Jump to:

22976 Posts in 11493 Topics by 2824 members

General Questions

SilverStripe Forums » General Questions » Dynamic drop down menus

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: 1297 Views
  • designerdre
    Avatar
    Community Member
    19 Posts

    Dynamic drop down menus Link to this post

    Hello again SilverStripe world,

    I'm using the following code to pull the first level of my Nav:
    <ul>
           <% control Menu(1) %>
                 <li><a class="$LinkingMode" href="$Link" title="Go to the &quot;{$Title}&quot; page">$MenuTitle</a></li>
             <% end_control %>
        </ul>

    Pretty straight forward. I need now to go a step further and also have it pull my level 2 items if they exist. Here is what in my mind should work:

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

    Is this the best way to go about doing this? Of course coupled with the right css to make drop drop down show or hide.

    thanks!

  • quamsta
    Avatar
    Community Member
    29 Posts

    Re: Dynamic drop down menus Link to this post

    This looks fine. If you were really nitpicking, I guess you could put the sub navigation into its own include file. But that might be pushing it.

    Looks great!

  • banal
    Avatar
    Community Member
    901 Posts

    Re: Dynamic drop down menus Link to this post

    You should use the "Children" control for the sub-menu. Menu(2) won't work inside a Menu(1) control.
    Best - Roman

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