The Techjoomla Blog

Stay updated with all the latest happenings at Techjoomla. From news about the developments in your favourite extensions to Tips & Tricks about the Joomla CMS, Framework & Development.

Posted by on in Joomla Development
  • Font size: Larger Smaller
  • Hits: 7124
  • Comments

How to use two layouts from same view for two submenus

Have you ever came across a situation, when working on a joomla component- you need two sub-menus to be shown in admin backend which belong to same view and different layouts?
If yes, then you must have noiced that this does not work as expected. 
 
Here's the solution for the same.
 
Suppose there are two submenus - this is the PHP code to add two submenus -
$reports=true;
JSubMenuHelper::addEntry(JText::_('COM_JGIVE_REPORTS'),'index.php?option=com_jgive&view=reports&layout=default',$reports);
JSubMenuHelper::addEntry(JText::_('COM_JGIVE_PAYOUT_REPORTS'),'index.php?option=com_jgive&view=reports&layout=payouts',$reports);
As you can see the 'view' for 2 submenus is same and 'layouts' are different
index.php?option=com_jgive&view=reports&layout=default
index.php?option=com_jgive&view=reports&layout=payouts
 
So when you browse to one of above mentioned views - you will see both submenus as active as shown in image below -
 
both-submenus-active
 
 
 
 
 
 
TO fix this you will need to add some jquery code to not show other submenu as active.
 
FILE - view=reports&layout=default
$document=JFactory::getDocument();
//override active menu class to remove active class from other submenu
$menuCssOverrideJs="$(document).ready(function()
{
$('ul>li> a[href$=\"index.php?option=com_jgive&view=reports&layout=payouts\"]:last').removeClass('active');
});";
$document->addScriptDeclaration($menuCssOverrideJs);
 
FILE - view=reports&layout=payouts
$document=JFactory::getDocument();
//override active menu class to remove active class from other submenu
$menuCssOverrideJs="$(document).ready(function(){
$('ul>li> a[href$=\"index.php?option=com_jgive&view=reports&layout=default\"]:last').removeClass('active');
});";
$document->addScriptDeclaration($menuCssOverrideJs);
After adding above code in those two layouts you will see that only the current submenu is shown as active.
one-submenu-active
It works well on joomla 2.5.x. :)
Rate this blog entry:

Developer at Techjoomla & responsible for making sure you get a bug free, quality releases on time!


* Music, Coffee, Colors, Piano, Stories, Web, Lappy, Green trees and Blue sky.


* Coder, Blogger, Workaholic at work, Twitaholic at home, Writes lines of code & paragraphs of stories, Living and loving open source.


* Aiming for excellence in open source - "Let there be peace and free code pieces!"


* Inspired by — 'You must be the change you wish to see in the world. - M. K. Gandhi'​

blog comments powered by Disqus