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

Alternate menu/theme based on page


Reply

4 Posts   1652 Views

Avatar
AlaVive

28 September 2009 at 5:38am Community Member, 42 Posts

I'm working on a large site that has three different menus and three different themes to be displayed based on the section of the site being visited. Ideally, I wouldn't have to maintain three different templates (especially as I continue to receive changes to the layout while I'm trying to build the CMS for it).

Provided I can solve the issue of switching menus based on the site section, the themes are similar enough that I can allow the user to select the proper CSS for a page within the CMS (according to http://www.silverstripe.org/archive/show/60032#post60032).

I've created the different menus and have them displaying correctly when hard-coded into the template, and I've managed to get them to display according to the following test:

<% if URLSegment == chickens %>
   <% include ChickenNavigation %>
   <% else %>
   <% include Navigation %>
<% end_if %>

The obvious problem is the utter lack of flexibility for creating new pages that display the proper menu.

It would be fine to say, "If you want to display the chickens menu, you have to add 'chickens' somewhere in the page title," or "Select the menu you want to display from the CMS." But, I can't figure out how to modify any effort I've yet put forth to offer either of those capabilities ;-).

What's the better way to handle this?

Avatar
zenmonkey

28 September 2009 at 5:57am Community Member, 528 Posts

What about adding a drop down field to the CMS with your different Menu Types then create functions that check against that selection in your Page_Controller.

function CheckChickens() {
if ($this->MenuType == "Chickens") {
return true;
}
else { return false; }
}


That way in you template you would do:

<% if CheckChickens %>
<% include ChickenNavigation %>
<% elseif CheckOther %>
<% include OtherNavigation %>
<% elseif etc %>
<% end_if %>

You could also create these sort of Check controllers against other parameters including Parent pages etc. I use the same sort of thing to display images certain class of image on my website. If the page itself doesn't specify this particular type of image it uses the image from the parent page, and if the parent page doesn't have this sort of image it reverts to a default.

Avatar
AlaVive

28 September 2009 at 6:58am Community Member, 42 Posts

Genius.

It works like a dream. Furthermore, I actually set the function to check against the PageStyle drop down, which combines both the CSS and menu modifications in one.

Thank you (again)!

Avatar
anujkryadav

8 January 2010 at 2:21am Community Member, 30 Posts

hello AlaVive
i too have the same requirement,can you please explain me the way to create different menu ...if possible do post the code and the pages where i need towrite the code

thank you in advance