Menu.. sub menu items making main menu item current.

Topics: Core, Customizing Orchard, General, Troubleshooting, Writing themes
Aug 20, 2012 at 2:40 PM

Bit of a tongue twister I think... and hard to explain

basically along the top menu I have 

Home | Products | Contact us

Under the products there is a drop down list

Home Products
Motor Products

Now when I click Home / Products / Contact Us

the CSS has current added to the class.. Now if I navigate to "Products >> Home Products" i want "Products" to be the current tab as "Home products" is a sub of this page.

Hope that is clear I'm sure someone has done this  

Aug 20, 2012 at 3:16 PM

IN CASE ANYONE ELSE NEEDS A QUICK FIX!

There should be a better way but I sorted out my problem so... in

Core\Shapes\Views\MenuItem.cshtml

change line 11 

   //if (requestUrl == modelUrl) { 
    if (requestUrl.Contains(modelUrl) && modelUrl != "" || requestUrl == modelUrl || requestUrl.Contains("HOME-PAGE") && modelUrl=="")
    { 
	    Model.Classes.Add("current");
    }

now when I make a sub page I add in the 
products/home-products
this should be OK as long as I am careful with the url names

If anyone has a better way or even a correct way please email me instructions
thanks

Developer
Aug 25, 2012 at 2:39 AM

If you navigate to Home Products, both Products and Home Products should have a "selected" class as well. You can target these classes with CSS to make them appear selected, or highlighted.

Nov 6, 2012 at 9:26 AM
Edited Nov 6, 2012 at 9:50 AM

How about checking the position of menuItem ?

It looks more logical using position information to mark the selected path.