Transfer parent title variable of active menu item


Author Message
Doug Evans

Posted: 9/20/2015
Quote message 

<div>Thanks to all of you I have been able to create a variable: $mytitle from the active parent menu item in Joomla 3.<br />
<br />
This is my code:<br />
<br />
<div><strong>Code:</strong></div>
<div>$menu = JFactory::getApplication()-&gt;getMenu();<br />
$parent = $menu-&gt;getItem( $menu-&gt;getActive()-&gt;parent_id );<br />
$parentname = $parent-&gt;title;<br />
$parentlink = JRoute::_( $parent-&gt;link . '&amp;Itemid=' . $parent-&gt;id );<br />
$menulevel = $menu-&gt;getActive()-&gt;level; $activename= $menu-&gt;getActive()-&gt;title;  <br />
$mytitle = ($menulevel == 1)?$activename:$parentname;<br />
echo $mytitle;</div>
<br />
<br />
This works great but now I need to use it on my submenu item (VMenuBlock). The code is as follows and I cannot seem to figure out how to place the variable so that it works?<br />
<br />
<div><strong>Code:</strong></div>
<div>function modChrome_vmenu($module, &amp;$params, &amp;$attribs)<br />
{<br />
if (!empty ($module-&gt;content)) {<br />
if (function_exists('VMenuBlock'))<br />
echo VMenuBlock(($module-&gt;showtitle != 0) ? $module-&gt;title : '', $module-&gt;content,<br />
$params-&gt;get('moduleclass_sfx'));<br />
else<br />
echo Block(($module-&gt;showtitle != 0) ? $module-&gt;title : '', $module-&gt;content,<br />
$params-&gt;get('moduleclass_sfx'));<br />
}<br />
}</div>
<br />
<br />
Any help or suggestions is appreciated!, Thanks! Doug</div>
 
Doug Evans

Posted: 9/20/2015
Quote message 

Sorry, it looked fine when I posted it![

quote=Doug Evans]
Thanks to your support I have been able to create a variable: $mytitle from the active parent menu item in Joomla 3.

This is my code:

Code:

$menu = JFactory::getApplication()->getMenu();
$parent = $menu->getItem( $menu->getActive()->parent_id );
$parentname = $parent->title;
$parentlink = JRoute::_( $parent->link .
'&Itemid=' .
$parent->id );
$menulevel = $menu->getActive()->level; $activename= $menu->getActive()->title;
$mytitle = ($menulevel == 1)?$activename:$parentname;
echo $mytitle;

This works great but now I need to use it on my submenu item (VMenuBlock).
The code is as follows and I cannot seem to figure out how to place the variable so that it works?

Code:

function modChrome_artvmenu($module, &$params, &$attribs)
{
if (!empty ($module->content)) {
if (function_exists('artxVMenuBlock'))
echo artxVMenuBlock(($module->showtitle != 0) ? $module->title : '', $module->content,
$params->get('moduleclass_sfx'));
else
echo artxBlock(($module->showtitle != 0) ? $module->title : '', $module->content,
$params->get('moduleclass_sfx'));
}
}


Any help or suggestions is appreciated!, Thanks! Doug

:*)