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

Menu with alternating colours


Reply

3 Posts   1080 Views

Avatar
mschiefmaker

20 October 2009 at 7:55am Community Member, 187 Posts

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

20 October 2009 at 8:04am (Last edited: 20 October 2009 8:06am), Community Member, 135 Posts

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

20 October 2009 at 8:09am Community Member, 187 Posts

Hi Thomas

Thank you, worked a treat!

Catherine