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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Archive /

Our old forums are still available as a read-only archive.

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

Dynamic javascript menu - how to do it?

Go to End

10 Posts   7063 Views


Community Member, 12 Posts

21 February 2008 at 9:54pm

Hi there,

I'm playing around with SilverStripe to see if I can use it for some future web sites. So far I like it a lot. Thanks for all the great work!

For one question, however, I couldn't find an answer in the forum:
Is there a way to build a menu that shows its children (recursively) when the mouse pointer hovers over it?
An example can be seen at (the site is horrible, I know, but it has the menu as I want it...).
There I used the Tigra Menu.
What I like about it is that it allows the user to navigate more quickly because he can see what is below each menu item when going over it with the mouse pointer.

Any hints?


Forum Moderator, 5523 Posts

21 February 2008 at 10:08pm

Rather then use javascript a much better idea is to use a css based dropdown navigation. We have used it for a few sites like (vertical nav rather then horizontal) . That uses one of the great dropdowns from Heres a menu that would be relatively easy to use for your site -

Design City

38 Posts

21 February 2008 at 10:24pm

Hi Jim,

two seperate problems here: one is getting from Silverstripe what you need, and the other is getting the style right.

From Silverstripe, you need an unordered list of the site content. You can get this by using control brackets in your template, something like this might work:

<% control Menu(1) %>
<li class="$LinkingMode $FirstLast"><a href="$Link">$MenuTitle</a></li>
<% if Children %><% control Children %>
<li class="$LinkingMode $FirstLast"><a href="$Link">$MenuTitle</a></li>
<% end_control %><% end_of %>
<% end_control %>

See more about creating menu systems in the forums and in the first tutorial (

Next you want to style that list with CSS and possibly javascript so that it looks like a dropdown menu, similar to the one you showed. There are HEAPS of code chunks around that will let you do that, for example or are both great, but you can easily google 100 more. Please keep in mind that CSS is able to accomplish 99% of dropdown menus, and Javascript should only be used to help older browsers (like IE<6) along where at all possible.

HTH :)


Community Member, 12 Posts

21 February 2008 at 11:41pm

Thanx for the fast feedback (both of you) and the emphasis on CSS over Javascript...

the thing is: I want the "entire" content - all levels deep not just two or three or four.
I found what you posted in the tutorials, but that's only for a certain amount of levels as I have to write the control block for every level I want in the menu.
Is there a way to do it recursively?
Without real coding I suppose not?


Forum Moderator, 5523 Posts

22 February 2008 at 9:23am

every level I want in the menu.

How many levels do you plan to support? You can do something like

<% control Menu(1) %>
<!-- top children -->
<% control Children %>
<!-- second level of children -->
<% control Children %>
<!-- Third Level -->
<% control Children %>
<!-- Fourth Level -->

and so on and so on till you iterate over all the levels you want. You can also wrap if statements around so you hide the 3rd/4th level if you are not on the second level etc. Multi level Menus can get a little crazy!


Community Member, 67 Posts

22 February 2008 at 9:23am

You are right in that it can't be done without new code, or at least I haven't found a way. For me it causes the memory to get exausted, with a 128M memory limit. The problem here is not with the children code, but with the templating system. for example, this code was what I was trying to get working (

<% if LinkOrSection = section %>
<% if Children %>
<% include Menu2 %>
<% end_if %>
<% end_if %>

I think that the teplating engine makes includes before evaluating conditions, which in this case causes infinite recursion.


Community Member, 12 Posts

22 February 2008 at 9:41pm

Edited: 22/02/2008 9:41pm

Well, actually I'd like to have a "menu depth" that reflects the depth in the site tree. With the solutions posted here - which I have tried already and which work fine (I'll post the solution once I'm completely done... IE, my troublesome friend) - I need to code every level in the template.
If I code let's say five levels and my customer adds a sixth level it doesn't appear in the menu. So I'd prefer a recursive solution that simply displays all there is.

Memory issues
I did something like this in my own cms and there wasn't a problem with the memory at all. Maybe it does when you have a deeply nested menu with a couple of 100000 items. I haven't tried that big a number of items, of course.


Community Member, 199 Posts

16 September 2008 at 10:08pm

"Heres a menu that would be relatively easy to use for your site -"

Hi Willr. You've helped me out before and I was hoping to get some more help! :) I want to use the above flyout menu that you recommended previously in this thread. I have all the CSS working etc but am unsure as to what code i need in the template for the actual flyout bit to work. First level appears perfectly but I can't get the flyout (sub menu) to appear. I've tried various control brackets but with no luck yet.

Your help is much appreciated as always.

Cheers. Briohny.

Go to Top