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.

Themes /

Discuss SilverStripe Themes.

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

Changing Menu Context

Go to End

2 Posts   1177 Views


Community Member, 70 Posts

19 April 2011 at 12:11pm

I've come across a situation in a current project where it would be useful to change the context of the menu that is showing on the left hand side (LHS). By this I mean at certain points in the site where the menu is missing I would like to substitute it with the menu from another part of the site.

The structure I have used it to have the children of the root form a top level menu and the top of the page, and their children a drop down menu. When a top level item is chosen the menu that is shown on the LHS is the children of that item [ in SS templating terms, Level(2) ].

There are 2 situations I have run into where there is no menu
1) Where only the top level menu item exists with no children
i) Search - I can get around this by providing perhaps suggested searches in the menu or advanced search
ii) Contact Us - This is in the top level as a requirement

2) When showing images for the image gallery with javascript turned off.

The latter is more important. I followed this tutorial, , and successfully have the image gallery module showing gallery and images for non JS compliance (ie no fancy lightbox popup). The menu works in the cases of Albums inside an ImageGalleryPage (a DataObject with a Page as a parent) but not in the case of an image (effectively a DataObject with a parent DataObject). I can only assume that as the parent Album does not extend Page (and thus SiteTree) it has no place in the site hierarchy.

What I would like to do is this: "In the case of showing an image I would like to populate the menu for the parent album"

Is there a way of doing in a way to reuse the existing menu mechanism, ie have Level(1), Level(2) etc be populated by the parent and not the currently selected image? I realize I could re-implement the menu in this special case but it seems like a lot of overhead, so some pointers forward would be appreciated




Community Member, 545 Posts

21 July 2011 at 6:44am

I don't know if you figured this out yet but you can use <% if Level(2) %><% else %><% control Parent %><% end_control %><% end_if %>