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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

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

navigation class


Go to End


9 Posts   2074 Views

Avatar
mhull

Community Member, 79 Posts

19 July 2009 at 9:54am

I have the following code in my navigation to add a class to my current page:

<li <% if LinkOrSection = section %>class="current"<% end_if %>><a href="$Link" >$MenuTitle</a> 

How would I add an alternate class onto this if within a certain link or section? for example:

<li <% if LinkOrSection = whats-new %>class="hidden"<% end_if %>><a href="$Link" >$MenuTitle</a> 

How would I add these together?

My full navigation code is:


	<ul id="topmenu" class="sf-menu sf-navbar">
<% control Menu(1) %>

<li <% if LinkOrSection = section %>class="current"<% end_if %>><a href="$Link" >$MenuTitle</a> 

<% if Children %> 
<% if URLSegment != whats-new %>
<% if URLSegment != work-with-us %>

<ul> 
<% control Children %> 
<li class="$LinkingMode"><a href="$Link" >$MenuTitle</a></li>
<% end_control %> 
</ul> 
<% end_if %> 
<% end_if %> 
<% end_if %> 
      </li> 
   <% end_control %> 
</ul>

Avatar
mhull

Community Member, 79 Posts

20 July 2009 at 1:17am

Okay, So I am trying the following, but it isnt reading the else. Am I writing it wrong? Any help would be much appreciated.


	<ul id="topmenu" class="sf-menu sf-navbar">
<% control Menu(1) %>

<li <% if LinkOrSection = section %>class="current"<% end_if %>><a href="$Link" >$MenuTitle</a> 

<% if Children %> 
<ul> 
<% control Children %> 
<li class="$LinkingMode"><a href="$Link" >$MenuTitle</a></li>
<% end_control %> 
</ul> 
<% end_if %> 
</li> 

<% else %>
<% if URLSegment = work-with-us %>
<li class="work"><a href="$Link">$MenuTitle</a></li> 
<% if Children %> 
<ul> 
<% control Children %> 
<li class="$LinkingMode"><a href="$Link" >$MenuTitle</a></li>
<% end_control %> 
</ul> 
<% end_if %> 

<% end_if %>
   <% end_control %> 
</ul>

Avatar
mhull

Community Member, 79 Posts

20 July 2009 at 9:28am

Why is the following not working?
If whats new use add this class to children, otherwise use other code. What am I doing wrong?


	<ul id="topmenu" class="sf-menu sf-navbar">
<% control Menu(1) %>

<li <% if LinkOrSection = section %>class="current"<% end_if %>><a href="$Link" >$MenuTitle</a> 

<% if Children %> 



<ul> 
<% control Children %> 

<% if URLSegment != what-we-ve-done %>
<% control Children %> 
<li class="plop"><a href="$Link" >$MenuTitle</a></li>
<% end_control %> 
<% end_if %>
<% else %>
<li class="$LinkingMode"><a href="$Link" >$MenuTitle</a></li>
<% end_control %> 
</ul> 


<% end_if %> 
      </li> 
   <% end_control %> 
</ul>

Any help? please anyone?

Avatar
AdamJ

Community Member, 145 Posts

20 July 2009 at 2:16pm

Edited: 20/07/2009 2:18pm

Can you post your site structure, eg:

- index
- about
- - staff
- - location
- services
- contact

Avatar
Willr

Forum Moderator, 5523 Posts

20 July 2009 at 3:37pm

mhull - you have used URLSegment != ... negation (!=) is not supported in ss templates. You have to do <% if URLSegment = blah %><% else %>.....

Avatar
mhull

Community Member, 79 Posts

20 July 2009 at 9:13pm

Many Thanks, with your comment and trial and error I finally got it to do what I wanted! Cheers

My final code, hiding certain children

   <ul id="topmenu" class="sf-menu sf-navbar"> 
<% control Menu(1) %>

<li <% if LinkOrSection = section %>class="current"<% end_if %>><a href="$Link" >$MenuTitle</a>

<% if Children %>

<% if URLSegment = whats-new %>
<ul>
<% control Children %>
<li class="hidden"><a href="$Link" >$MenuTitle</a></li> 
<% end_control %> 
</ul>


<% else %>


<% if URLSegment = work-with-us %>
<ul>
<% control Children %>
<li class="hidden"><a href="$Link" >$MenuTitle</a></li> 
<% end_control %> 
</ul>


<% else %>

<ul> 
<% control Children %>
<li class="$LinkingMode"><a href="$Link" >$MenuTitle</a></li> 

<% end_control %> 
</ul>
<% end_if %> 
<% end_if %> 
<% end_if %> 
</li> 
<% end_control %> 
</ul>

Avatar
AdamJ

Community Member, 145 Posts

20 July 2009 at 10:14pm

willr, this documentation isn't really correct then...

http://doc.silverstripe.org/doku.php?id=templates#if_blocks

mhull, according to those docs (if its supported) you can use else_if, so instead of having the second if statement within the else statement for the first if statement, you could use an else_if.

Avatar
Willr

Forum Moderator, 5523 Posts

20 July 2009 at 10:34pm

Actually I lie, != *is* supported according to the source in SSViewer. Whether it works or not well thats up to god. I was getting confused with <% if !$Val %>.. which is not implemented

Go to Top