Welcome Guest, Not a member yet? Register   Sign In
Automatically add a class to link for active page?
#1

[eluser]rebellion[/eluser]
I'm using the anchor function to create links around in my application, but I miss a (preferably automatic) function for adding a class to the link element, without having to check the URI segments all the time (which can be very messy). How do you guys solve this?
#2

[eluser]rogierb[/eluser]
I wrote a helper function that takes an array of links and checks them against the current URI. If a link matches, it adds a class: "active" to that link. An extension has been build to accomodate for submenu's,which is a whole different story

I guesss in your case, just pass the anchor to a helper function:
<code>Check_for_current_uri(anchor("some_controller/some_method/var1/var2", "title", array("class"=>"replace_this_with_active_class")))</code>

In that function check the current uri to the one in the link. Is it matches, replace the class, if not do nothing or remove the bogus class




Theme © iAndrew 2016 - Forum software by © MyBB