3435 Posts in 1026 Topics by 866 members
|Go to End|
8 July 2010 at 5:30pm
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?
8 July 2010 at 6:58pm
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?
8 July 2010 at 7:08pm
Sure, it's pretty straight forward at the moment, three pages.
<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>
8 July 2010 at 7:41pm
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.
<% control Menu(1) %>
<li><a href="$Link" class="$LinkingMode">$MenuTitle.XML</a></li>
<% end_control %>
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.
9 July 2010 at 8:45am
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:
<li class="first"><a href="home" class="current">Home</a></li>
<li><a href="about-us">About us</a></li>
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.
9 July 2010 at 9:56am Last edited: 9 July 2010 10:00am
It does that too, use <% if First %> or you can use $FirstLast
you will probably find this useful:
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.
9 July 2010 at 10:20am
Great! Got it working, thanks very much for your help!
|Go to Top|