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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

Dynamic drop down menus


Go to End


3 Posts   1898 Views

Avatar
designerdre

Community Member, 19 Posts

27 March 2009 at 5:35am

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

Community Member, 29 Posts

28 March 2009 at 7:51am

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
bummzack

Community Member, 904 Posts

30 March 2009 at 8:19pm

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