Welcome Guest, Not a member yet? Register   Sign In
Setting a menu item to "selected"
#1

[eluser]NateL[/eluser]
In creating a navigation menu, we usually have a class called "selected", which sets that navigation menu appart from other items, letting users know they're on that page.

What's a good way of setting a class to a list item, dynamically?

My current method is all done in the view - but I feel like I should be doing this a bit more efficiently. Any suggestions?

Code:
<?php $page = $this->uri->segment(2); ?> //First segment is /admin/
    

     <ul id="menu">
        <li &lt;?php if ($page == ''){ echo 'class="selected"'; } ?&gt;><a href="/admin">Dashboard</a></li>
        <li &lt;?php if ($page == 'users'){ echo 'class="selected"'; } ?&gt;><a href="/admin/users">Users</a></li>
       ......
      </ul>&lt;!--end menu--&gt;


Messages In This Thread
Setting a menu item to "selected" - by El Forum - 06-16-2010, 02:16 PM
Setting a menu item to "selected" - by El Forum - 06-16-2010, 02:38 PM
Setting a menu item to "selected" - by El Forum - 06-16-2010, 02:39 PM
Setting a menu item to "selected" - by El Forum - 06-16-2010, 08:56 PM
Setting a menu item to "selected" - by El Forum - 06-25-2010, 03:04 PM
Setting a menu item to "selected" - by El Forum - 08-14-2011, 05:52 PM
Setting a menu item to "selected" - by El Forum - 04-14-2012, 03:25 PM
Setting a menu item to "selected" - by El Forum - 04-14-2012, 05:01 PM
Setting a menu item to "selected" - by El Forum - 04-14-2012, 05:20 PM



Theme © iAndrew 2016 - Forum software by © MyBB