Welcome Guest, Not a member yet? Register   Sign In
tell the nav menu what page is loaded, hightlight item
#1

[eluser]deco10[/eluser]
I need to change the list item depending on whether or not it is the currently selected page.

I realize there is 1001 ways to do this, but I wondered if CI had something built in to stop me from having ternary operators all over the place. If CI doesn't have a built in solution for this, any suggestions about how you would do this clean and concise?


Thanks!
#2

[eluser]TheFuzzy0ne[/eluser]
Export your navigation to a helper/library, and have it load a view and loop through the options doing whatever it needs to. Perhaps this isn't the solution you were after, but it works for me. Smile
#3

[eluser]Dam1an[/eluser]
I keep my navigation in a seperate view file (where I do use the ternary operator, but it's out of sight, out of mind. Pretty much the same as Fuzzy's suggestion of a helper/library
#4

[eluser]slowgary[/eluser]
This should be in the CSS spec... something like a:current, although it wouldn't allow you to style that link's parent element until they solve the problem of parent selectors.
#5

[eluser]TheFuzzy0ne[/eluser]
A thought that just occurred to me - You could also have a helper that has a function similar to the form helper's set_value(), only it can return a class/id as needed.

Code:
function set_nav_item($name="", $segment_num=1)
{
    return (($name && $this->uri->segment($segment_num) == $name) ? ' class="selected"' : '');
}




Theme © iAndrew 2016 - Forum software by © MyBB