Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.
- Index
- » MetaMod Pro
- » MetaMod Pro General Support
- » Split Menu - Detecting Children of...
Split Menu - Detecting Children of Active Menu Item
Split Menu - Detecting Children of Active Menu Item
Hey Mr Wizard -
I'm having a challenge in MMP 3.6 on J! 1.7.0
The big picture - I am trying to extend a recipe you posted here:
http://www.metamodpro.com/forums/topic?id=215
The desired outcome in Pseudocode:
Case No Active menu - return filler module
Case Active menu level >= 1 - return Split menu module
Case Active menu level = 0 and count active menu item children > 0 - return Split menu module
Else - return filler module
<<SNIP - edited to remove code that didn't work - leaving only the issue and solution for others wanting an enhanced split menu module. >>
Help me coach! Not sure what to try next.
BTW, does Jom_Genius have a check for children
OR if module content other than the Heading has length > 0 (A way to test module 49 for content other than it's title as a back door way to test for any children?)
19-Sep-11 10:33:36
Re: Split Menu - Detecting Children of Active Menu Item
Hi Duke,
I replied to your other post on http://www.metamodpro.com/forums/topic?id=215#p3750 with a piece of code which works - can you try that and see how you get on?
Cheers,
Stephen
Re: Split Menu - Detecting Children of Active Menu Item
Brilliant, as always. Thank you sir.
My final code ...
For those looking for a split menu solution that shows a submenu or, if none, another module to fill the space, here is the final code I used where module 49 is the split menu module with display level starting at level 2. The level 1 menu item being displayed becomes the Split Menu's title. Module 59 is another module to fill the space when there are no sub-menu items to show in the split menu. Module 60 is another module to fill the space when the page being displayed is accessed through another menu / the main menu is inactive. (Remove "} else { return 59;" and "} else { return 60;" if you don't want anything displayed other than the split menu.) Change 'menu-main' to the value you see for "menu type" when viewing the list of menus in the Menu Manager.
Code:
$menu = &JSite::getMenu();
$active = $menu->getActive();
if ($active->menutype == 'menu-main') {
if (@$active->level > 1) {
$topParent = $menu->getItem( $active->tree[0] );
$changes->mod(49)
->title($topParent->title . " - Sub-Menu:");
return 49; // item in submenu active
} else {
$items = $menu->getItems(array("parent_id"), array($Itemid));
if (count($items) > 0) {
$changes->mod(49)
->title($menu_genius->info( "title" ) . " - Sub-Menu:");
return 49; // active level1 item has submenu
} else {
return 60; // active level1 has no submenu
} } } else {
return 59; // main menu not active
}
I love how easy it is to do this with MMP!
Re: Split Menu - Detecting Children of Active Menu Item
Re: Split Menu - Detecting Children of Active Menu Item
I needed to supplement this as I was getting an error for pages selected from non-menu modules as it tries to render the sub-menu for an inactive menu item.
The error was
Notice: Trying to get property of non-object ... in mod_metamod/helper.php(597) : eval()'d code on line 3
So I added @ to suppress the error on line 3, yet the result is the mod not rendering at all instead of the else clause (return 59) being rendered.
Line 3
Code:
if (@$active->menutype == 'menu-main') {
I tried a wrapper code to do a preliminary test for non-object to trap the eval failure and show a substitute module.
I added
Code:
if (!is_object($active)) { return 58; }
but, curiously, it was not enough - mod didn't render even though Debug advanced said Includes 58.
So instead I'm detecting whether the item displayed is from com_content.
Current code:
Code:
if ($option == 'com_content') {
$menu = &JSite::getMenu();
$active = $menu->getActive();
if (!is_object($active)) { return 58; } // no active menu object
if ($active->menutype == 'menu-main') {
if (@$active->level > 1) {
$topParent = $menu->getItem( $active->tree[0] );
$changes->mod(49)
->title($topParent->title . " - Sub-Menu:");
return 49; // item in submenu active
} else {
$items = $menu->getItems(array("parent_id"), array($Itemid));
if (count($items) > 0) {
$changes->mod(49)
->title($menu_genius->info( "title" ) . " - Sub-Menu:");
return 49; // active level1 item has submenu
} else {
return 60; // active level1 has no submenu
} } } else {
return 57; // active menu not main menu
} } else {
return 56; // main menu not active - not com-content
}
and at last, this renders 56 instead of not rendering. Not sure why it worked and is_object didn't.
The page link triggering failure is following a link to full page event view in a JEvents module listing coming events, but I suspect following in-module links from photo gallery random images and similar will cause the same issue.
Re: Split Menu - Detecting Children of Active Menu Item
- Index
- » MetaMod Pro
- » MetaMod Pro General Support
- » Split Menu - Detecting Children of...
Board Info
- Board Stats:
- Total Topics:
- 1689
- Total Polls:
- 6
- Total Posts:
- 5943
- Total Posts Today:
- 1
- User Info:
- Total Users:
- 7638
- Newest User:
- moner86658
- Members Online:
- 0
- Guests Online:
- 146
- Online:
- There are no members online
Forum Legend:
Topic
New
Locked
Sticky
Active
New/Active
New/Locked
New Sticky
Locked/Active
Active/Sticky
Sticky/Locked
Sticky/Active/Locked