Jump to:

3401 Posts in 979 Topics by 855 members

Template Questions

SilverStripe Forums » Template Questions » Customizing Menu

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

Page: 1
Go to End
Author Topic: 706 Views
  • PeWa
    Avatar
    Community Member
    1 Post

    Customizing Menu Link to this post

    Hi all,

    I'm not firm with Silverstripe and I want to place a sub in a sidebar with the following properties:

    First If the submenu will NOT be displayed when the parent page has the ID = 11.

    Second I wish that I just at this submenu the first of several <li> tags deposited in the CLASS attribute "firstItem".
    So I could in fact represent the sub-menu with dashes between the menu items:

    MP1 | MP2 | MP3 | MP4 etc. ..

    Can you give me one probably a tip?

    best regards
    Peter

  • ampedup
    Avatar
    Community Member
    133 Posts

    Re: Customizing Menu Link to this post

    <% if Menu(2) %>
    <% if ID != 11 %>
       <ul class="subNavigation">
          <% control Menu(2) %>
             <li class="liSubNavigation $LinkingMode $FirstLast">
                <a href="$Link" title="Go to the $Title.XML page" class="aSubNavigation $LinkingMode $FirstLast">$MenuTitle.XML</a> <% if Last %><% else %> | <% end if %>
             </li>
          <% end_control %>
       </ul>
    <% end_if %>
    <% end_if %>

    There are a few parts to explain.

    We check if the current page id is not equal to 11:

    <% if ID != 11 %>
    ...
    <% end_if %>

    We add the property $FirstLast to the class of the <li>/<a> which returns first or last if either of these cases are true. Note, this will make the class first, not firstItem as requested.
    http://doc.silverstripe.org/sapphire/en/reference/built-in-page-controls#and-lt-if-first-and-gt-and-lt-if-last-and-gt-and-lt-if-middle-and-gt-firstlast

    We add the dash by doing an if else on the last item like so:

    <% if Last %><% else %> | <% end if %>

    Hope this gives you what you want or at least the tools to start playing around to do what you want.

    706 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.