Jump to:

5537 Posts in 1737 Topics by 1223 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Setting the selected state for a static menu

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1323 Views
  • pingu
    Avatar
    Community Member
    75 Posts

    Setting the selected state for a static menu Link to this post

    Hi guys,

    Another question from a silverstripe novice

    I've got a website for which I need to define static navigation in the templates - reason being that the design shows 3 levels of navigation, however they are all 1st level nav items. That is - they are all important pages but are grouped in 3 different styles of navigation across the design - they are each their own section and not nested within anything else.

    My question is, if I have set them up as static navigation items in the page template, is there a way I can apply logic within these items to set the current items state to selected? I'm not sure how to use conditions within HTML elements in templates.

    What I would like to achieve is something like this:

    <li <% if $URLSegment == "about us" class="selected" ><a href="/about-us">About Us</a></li>

  • pingu
    Avatar
    Community Member
    75 Posts

    Re: Setting the selected state for a static menu Link to this post

    Have solved this by adding a function to the PageControllor:

    function IsSelected($section){
          if($section == $this->CurrentPage())
             return 'class="selected"';
       }

    1323 Views
Page: 1
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.