21288 Posts in 5733 Topics by 2602 members
| Go to End | Next > | |
| Author | Topic: | 1051 Views |
-
navigation class

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> -
Re: navigation class

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> -
Re: navigation class

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?
-
Re: navigation class

20 July 2009 at 2:16pm Last edited: 20 July 2009 2:18pm
Can you post your site structure, eg:
- index
- about
- - staff
- - location
- services
- contact -
Re: navigation class

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 %>.....
-
Re: navigation class

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> -
Re: navigation class

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.
-
Re: navigation class

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
| 1051 Views | ||
| Go to Top | Next > |


