Active sub-menu for pages not included in menu

If you have questions about using mojoPortal, you can post them here.

You may want to first review our site administration documentation to see if your question is answered there.

This thread is closed to new posts. You must sign in to post in the forums.
1/19/2011 2:12:05 PM
Gravatar
Total Posts 22

Active sub-menu for pages not included in menu

Hi,

Let's say I have a site with a menu and sub-menu displayed in the header. When I access a page, say:

Level 1 > Level 2 > My current page

The "Level 2" button in my menu is highlighted when I am on "My current page". However if "My current page" is not set to be included in the menu, then the Level 2 (and Level 1) menu options will not be highlighted.

Is there a workaround so the the correct level stays highlighted/active in the menu even if the sub-page is not included in the menu?

1/19/2011 7:21:50 PM
Gravatar
Total Posts 1203
Proud member of the mojoPortal team

Help support mojoPortal!
Add-on modules

Re: Active sub-menu for pages not included in menu

I'm not aware of any method to force highlighting in the menu, but as a workaround, you could include breadcrumbs in the layout.master file of your skin.

Jamie

1/20/2011 7:19:30 AM
Gravatar
Total Posts 22

Re: Active sub-menu for pages not included in menu

Thanks Jamie. I'm already using breadcrumbs, so the visitor is not completely lost, but it would be way better if the sub-menu would also indicate in which section he is, even if the current page is not included in the menu.

1/20/2011 9:26:40 AM
Gravatar
Total Posts 18439

Re: Active sub-menu for pages not included in menu

Its just the way the menu control works, it would highlight if it had active child items but since the child is not included in the menu the menu does not know it has an active child item. No easy solution comes to mind.

5/23/2011 10:19:57 AM
Gravatar
Total Posts 5

Re: Active sub-menu for pages not included in menu

I'm not so sure whether it's a good idea or not, but placing following code in SiteMenu.ascx.cs will do the job

menuItem = menu.FindItem(valuePath);
                    //If the page is not Included In Menu, the above line of code wont work, following code is workaround for it
                    //=========
                    if (menuItem == null)
                    {
                        if (!string.IsNullOrWhiteSpace(valuePath))
                        {
                            int lastSeperatorIndex = valuePath.LastIndexOf(menu.PathSeparator);
                            while (lastSeperatorIndex > 0)
                            {
                                valuePath = valuePath.Substring(0, lastSeperatorIndex);
                                menuItem = menu.FindItem(valuePath);
                                if (menuItem != null)
                                    break;
                                lastSeperatorIndex = valuePath.LastIndexOf(menu.PathSeparator);
                            }
                        }
                    }
                    //=========

5/24/2011 7:57:07 AM
Gravatar
Total Posts 18439

Re: Active sub-menu for pages not included in menu

Hi,

Thanks for this, it looks like a good solution to me. But can you be more specific about where it goes, ie what line number before and after this code? 

Thanks,

Joe

5/24/2011 11:42:23 AM
Gravatar
Total Posts 5

Re: Active sub-menu for pages not included in menu

Hi Joe

As of version 2.3.6.2, I placed this code after the line number 413.

406: if (!didSelect)
407:            {
408:                valuePath = SiteUtils.GetActivePageValuePath(siteMapDataSource.Provider.RootNode, startingNodeOffset);

409:

410: if (valuePath.Length > 0)

 

411:                {
412:                   MenuItem menuItem;
413:                    menuItem = menu.FindItem(valuePath);

 

 

5/24/2011 12:58:48 PM
Gravatar
Total Posts 18439

Re: Active sub-menu for pages not included in menu

Thanks! I will make this change.

Best,

Joe

5/29/2011 11:51:33 PM
Gravatar
Total Posts 2

Re: Active sub-menu for pages not included in menu

I've downloaded version 2.3.6.5 with the change mentioned above but used function IsNullOrWhiteSpace doesn't work with dot.net 3.5, and solution doesn't compile in that framework.

So I changed it with similar one (MS documentation):

!(String.IsNullOrEmpty(valuePath) || valuePath.Trim().Length == 0)

Best,

Giuseppe

5/30/2011 8:05:35 AM
Gravatar
Total Posts 18439

Re: Active sub-menu for pages not included in menu

This is already fixed in the source code repository, I encountered this myself when packaging the 3.5 .NET packages for the new 2.3.6.6 release.

Best,

Joe

You must sign in to post in the forums. This thread is closed to new posts.