Jump to content

Add class "current" to all parents in a multi-level menu


Claus
 Share

Recommended Posts

Hello there!

I have a question regarding the "renderNav" function used in the ‘intermediate’ site-profile. I have a multi-level menu system going by using the renderNav function, and I’d like to extend the default "renderNav" function to also mark all the parents of any given page with "current".

I think I have to modify this line from the "renderNav" function:

$out .= $item->id == wire('page')->id ? "<li class='current'>" : "<li>";

… specifically adding something along the lines of foreach parent of the itemid "<li class='current'>" else "<li>", but is there a neat way of putting that into the existing line? Or how would you do it?

Thanks!

Link to comment
Share on other sites

Not tested, but try this:

$page = wire('page');
$out .= $item->id == $page->id || $page->parents()->has($item) ? "<li class='current'>" : "<li>";
Edited by diogo
corrected the code
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...