Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

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

Dynamic drop down menus


Reply

3 Posts   1344 Views

Avatar
designerdre

27 March 2009 at 5:35am Community Member, 19 Posts

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!

Avatar
quamsta

28 March 2009 at 7:51am Community Member, 29 Posts

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!

Avatar
banal

30 March 2009 at 8:19pm Community Member, 901 Posts

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