How to access Joomla menu parameters anywhere inside Joomla code?

 

Screenshot shows menu item parameters for Joomla - Content - Featured Articles Menu

 

Here are two code snippets inside Joomla that lets you access menu parameters anywhere inside Joomla!

 

1. To access Current Menu parameters

$app = JFactory::getApplication();
// Get active menu
$currentMenuItem = $app->getMenu()->getActive();
// Get params for active menu
$params = $currentMenuItem->params;
// Access param you want
$yourParameter = $params->get('yourParameter');

 

2. To access Menu parameters from a known Itemid

$app = JFactory::getApplication();
// Get Itemid from URL
$input  = JFactory::getApplication()->input;
$itemId = $input->get->get('Itemid', '0', 'INT');
// Get menu from Itemid
$menuItem = $app->getMenu()->getItem($itemId);
// Get params for menuItem
$params = $menuItem->params;
// Access param you want
$yourParameter = $params->get('yourParameter');

 

That was easy-peasy! Wasnt it?

Feel free to add comments!