• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Nav highlighting help - how do you track which page the user is on and highlight the appropriate link in the navbar?

#1
[eluser]Exeneva[/eluser]
I'm currently new to CI and trying hard to learn. I've set up a basic site using a combination of CI, Bootstrap by Twitter, and HTML5Boilerplate at http://www.illustrosity.com

My question concerns nav highlighting and tracking what page the user is currently on. For example, when you go to the homepage, the link "Home" is active and highlighted in the navbar.

However, when you go to the 2D page (http://www.illustrosity.com/home/category/1/2d), the "Home" link is still active and highlighted.

How do you track what page the user is on?

#2
[eluser]Samus[/eluser]
you can uri_string in the URL helpers.

There are several ways of achieving this really, you can even do it in pure CSS.

a CI solution could be something like this:

Code:
<li&lt;?=if(uri_string == 'home' OR '') : ' class="active">' endif; ?&gt;><a href='home url'>Home</a></li> : <li><a href="home url">Home</a></li>
Then you'd do that for each nav item, that's abit messy, but it works.

There are loads of other methods, just google them.

#3
[eluser]Exeneva[/eluser]
I actually found quite an elegant solution in another thread: http://ellislab.com/forums/viewthread/158196/#763146

Thanks for the suggestion above - it works, but I'm trying to stay away from any messy solutions at the moment.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.