Getting Menu Parameters from Joomla

I think JParameter is obsolete in Joomla! 3.x, so the answer now is something like:

 $app = JFactory::getApplication();
 $menuitem   = $app->getMenu()->getActive(); // get the active item
 $menuitem   = $app->getMenu()->getItem($theid); // or get item by ID
 $params = $menuitem->params; // get the params
 print_r($params); // print all params as overview

You can get the menu_image variable by doing:

 echo $params->get('menu_image');

Or first check if it's filled in and, if it is, echo it:

// using get() with a second parameter makes it fall back to this if nothing is found
$menu_image = $params->get('menu_image', false);
if ($menu_image && strlen($menu_image)) {
   echo "<img src='$menu_image'/>";
}

Or, using a tertiary operator:

$menuimg = $params->get('menu_image')
echo strlen($menuimg) ? "<img src='$menuimg'/>" : '';

You need to use the JParameter class to read the params. Try something like this:

$item = $menu->getItem($menuId);
$params = new JParameter($item->params);
$myParam = $params->get('theParamIwant');

It doesn't work

Try to use this:

$params = $menus->getParams($menuId);
$myParam = $params->get('theParamIwant');

Tags:

Php

Joomla