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.

Template Questions /

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

Customizing Menu

Go to End

2 Posts   1280 Views


Community Member, 1 Post

5 June 2012 at 7:55am

Hi all,

I'm not firm with Silverstripe and I want to place a sub in a sidebar with the following properties:

First If the submenu will NOT be displayed when the parent page has the ID = 11.

Second I wish that I just at this submenu the first of several <li> tags deposited in the CLASS attribute "firstItem".
So I could in fact represent the sub-menu with dashes between the menu items:

MP1 | MP2 | MP3 | MP4 etc. ..

Can you give me one probably a tip?

best regards


Community Member, 135 Posts

6 June 2012 at 12:49pm

Edited: 06/06/2012 12:50pm

<% if Menu(2) %>
<% if ID != 11 %>
	<ul class="subNavigation"> 
		<% control Menu(2) %>
			<li class="liSubNavigation $LinkingMode $FirstLast">
				<a href="$Link" title="Go to the $Title.XML page" class="aSubNavigation $LinkingMode $FirstLast">$MenuTitle.XML</a> <% if Last %><% else %> | <% end if %>
		<% end_control %>
<% end_if %>
<% end_if %>

There are a few parts to explain.

We check if the current page id is not equal to 11:

<% if ID != 11 %>
<% end_if %>

We add the property $FirstLast to the class of the <li>/<a> which returns first or last if either of these cases are true. Note, this will make the class first, not firstItem as requested.

We add the dash by doing an if else on the last item like so:

<% if Last %><% else %> | <% end if %>

Hope this gives you what you want or at least the tools to start playing around to do what you want.