17691 Posts in 4607 Topics by 2180 members
General Questions
SilverStripe Forums » General Questions » Active link
General questions about getting started with SilverStripe that don't fit in any of the categories above.
Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba
|
Page:
1
|
Go to End | |
| Author | Topic: | 996 Views |
-
Active link

9 February 2010 at 11:32pm
Hi, I'm tying to get my navigation menu to highlight which page you are on using this code
<ul id="menu">
<% control getTopNav %>
<% if First %>
<li class="first<% if LinkorSection = section %> active<% end_if %>"><a href=$Link>$MenuTitle</a></li>
<% else_if Last %>
<li class="last"><a href=$Link>$MenuTitle</a></li>
<% else %>
<li><a href=$Link>$MenuTitle</a></li>
<% end_if %>
<% end_control %>
</ul>It highlight the hompage when your on that page but not on any others??
Any ideas would be great, thanks.
-
Re: Active link

10 February 2010 at 2:08am Last edited: 10 February 2010 2:09am
Hi
In your code you're only highlighting the first item, since you only apply the "active" class in the <% if First %> block.The whole code can be written much much simpler, like this:
<ul id="menu">
<% control getTopNav %>
<li class="$FirstLast $LinkOrSection"><a href=$Link>$MenuTitle</a></li>
<% end_control %>
</ul>Because $FirstLast will output "first" for the first item, and "last" for the last item.. no need for the if-else blocks. Same goes for $LinkOrSection. It will either output "link" or "section" (see here for a reference of these controls: http://doc.silverstripe.org/doku.php?id=built-in-page-controls).
The only thing you need to do is change your stylesheet from .active to .section -
Re: Active link

10 February 2010 at 2:23am
Thanks for the reply,
I just swapped that code for mine and changed the class in the stylesheet but seem to get the same effect?
-
Re: Active link

10 February 2010 at 4:39am
Did you try flushing the template-cache of the page? (by appending ?flush=1 to the URL)
-
Re: Active link

10 February 2010 at 5:01am Last edited: 10 February 2010 5:02am
I tried flushing it, the funny thing is that now it's suddenly highlighting on the homepage and the news pages but none of the others.
EDIT -
I had only flushed the news page and not the rest, now i am they seem to be working too!
Thanks for the help!
| 996 Views | ||
|
Page:
1
|
Go to Top |


