Jump to:

23013 Posts in 11540 Topics by 2825 members

General Questions

SilverStripe Forums » General Questions » navigation class

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

Page: 1 2
Go to End
Author Topic: 1259 Views
  • mhull
    Avatar
    Community Member
    79 Posts

    navigation class Link to this post

    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>

  • mhull
    Avatar
    Community Member
    79 Posts

    Re: navigation class Link to this post

    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>

  • mhull
    Avatar
    Community Member
    79 Posts

    Re: navigation class Link to this post

    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?

  • AdamJ
    Avatar
    Community Member
    145 Posts

    Re: navigation class Link to this post

    Can you post your site structure, eg:

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

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: navigation class Link to this post

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

  • mhull
    Avatar
    Community Member
    79 Posts

    Re: navigation class Link to this post

    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>

  • AdamJ
    Avatar
    Community Member
    145 Posts

    Re: navigation class Link to this post

    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.

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: navigation class Link to this post

    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

    1259 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.