Jump to:

3393 Posts in 976 Topics by 852 members

Template Questions

SilverStripe Forums » Template Questions » LinkingMode in menu

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

Page: 1
Go to End
Author Topic: 2163 Views
  • ruskiwi
    Avatar
    Community Member
    5 Posts

    LinkingMode in menu Link to this post

    Hi all,

    I'm trying to use class="$LinkingMode" in my menu items, only they all return "current" no matter what page I am on! Why would this be and how can I fix it?

    Thanks!

  • TotalNet
    Avatar
    Community Member
    181 Posts

    Re: LinkingMode in menu Link to this post

    Hi ruskiwi

    Welcome to the forum.

    That is odd, it's probably due to the control loop you have set up. Can you paste or attach the template code you have for the navigation?

    Cheers,

    Rich

  • ruskiwi
    Avatar
    Community Member
    5 Posts

    Re: LinkingMode in menu Link to this post

    Sure, it's pretty straight forward at the moment, three pages.

    <div class="menu">
    <ul>
    <li><a href="home" class="$LinkingMode">Home</a></li>
    <li><a href="about-us" class="$LinkingMode">About us</a></li>
    <li><a href="contacts" class="$LinkingMode">Contacts</a></li>
    </ul>
    </div>

  • TotalNet
    Avatar
    Community Member
    181 Posts

    Re: LinkingMode in menu Link to this post

    Cool, that explains it.

    Take a look at Navigation.ss in the blackcandy theme (in themes/blackcandy/temapltes/includes/) for an example...

    you don't need to enter each menu item manually, SilverStripe does that for you e.g.

    <ul>
    <% control Menu(1) %>
    <li><a href="$Link" class="$LinkingMode">$MenuTitle.XML</a></li>
    <% end_control %>
    </ul>


    That will create a li for each of the "top level" pages you create in the CMS, any pages you don't want to appear in the menu, simply un-check the tick box for "Show in Menus" in the behaviour tab in the CMS.

    I strongly recommend running through the tutorial it doesn't take long and explains all the basics, you can also get really far by taking the blackcandy theme as a working example and play around with that to figure out what you can do then apply it to your own theme.

  • ruskiwi
    Avatar
    Community Member
    5 Posts

    Re: LinkingMode in menu Link to this post

    Thanks for that. I did look through the tutorial and searched the forums. I got the menu working per the SS way but I do want the first item to differ from the others (it's a rounded end while others are all straight edged). So actually my code is:
    <div class="menu">
    <ul>
    <li class="first"><a href="home" class="current">Home</a></li>
    <li><a href="about-us">About us</a></li>
    </ul>
    </div>

    I want an additional class for the first item. Works fine in straight html and I thought using LinkingMode would return a "current" string on just the active page, but it returns the same string for all items regardless of which page I am on.

  • TotalNet
    Avatar
    Community Member
    181 Posts

    Re: LinkingMode in menu Link to this post

    It does that too, use <% if First %> or you can use $FirstLast

    you will probably find this useful:
    http://doc.silverstripe.org/built-in-page-controls#dataobjectset_options

    The navigation is working through a [data] set of pages with the context you specify (i.e. <% control Menu(1) %> where menu level 1 is the context) outside of the control loop you only have access to the methods and fields specific to the page [object] you are viewing at the time which is why $LinkingMode returns the same thing each time, the context is the same.

    The options you have are to use $FirstLast or <% if First %> which keeps the template clean and fully controlled by the CMS; or you can hard-code the menu and use other controls available e.g. <% if InSection(page-url) %> or by setting up a new control loop for each of the other pages with <% control Page(page-url or id) %> and you then have access to the methods/fields for that page [object] instead. If all else fails, you can create your own methods/fields in the Page class.

    Key thing is to remember the context of the method/field you are requesting.

    Cheers,

    Rich

  • ruskiwi
    Avatar
    Community Member
    5 Posts

    Re: LinkingMode in menu Link to this post

    Great! Got it working, thanks very much for your help!

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