CodeIgniter Forums
Automatically add a class to link for active page? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Automatically add a class to link for active page? (/thread-23249.html)



Automatically add a class to link for active page? - El Forum - 10-05-2009

[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?


Automatically add a class to link for active page? - El Forum - 10-05-2009

[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