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

Menu with alternating colours


Go to End


3 Posts   1504 Views

Avatar
mschiefmaker

Community Member, 187 Posts

20 October 2009 at 7:55am

I have a menu which creates its top level using code

<% control Menu(1) %>
<% if Children %>
<li ><a href="#" onFocus="if(this.blur)this.blur()" class="$LinkingMode" >$MenuTitle.XML ...

I want to change this so that it every second menu option is a different colour i.e. odd it is organge, even it is grey.

To this I want to test against its order in the sitetree (unless someone thinks there is a better way) but I am not sure what this variable is called?

Thanks

Catherine

Avatar
Nobrainer Web

Community Member, 138 Posts

20 October 2009 at 8:04am

Edited: 20/10/2009 8:06am

The below should work (see http://doc.silverstripe.org/doku.php?id=built-in-page-controls)

<% control Menu(1) %>
<% if Children %>
<li class="$EvenOdd"><a href="#" onFocus="if(this.blur)this.blur()" class="$LinkingMode" >$MenuTitle.XML ...

$EvenOdd will return even or odd, so just make two css classes with these names and style as you wish.
--

Thomas B. Nielsen
http://www.lund-co.dk

Avatar
mschiefmaker

Community Member, 187 Posts

20 October 2009 at 8:09am

Hi Thomas

Thank you, worked a treat!

Catherine