Reputation: 7894
I'm trying to get parameters from the menu table in Joomla. What I have below is working in the sense that it is returning the parameters.
$menu = &JSite::getMenu();
$item = $menu->getItem($menuId)->params;
print $items;
However, It's returning them in plain text, as if I had just queried the column and returned the params contents.
Can someone tell me how to return this as an Object or Array so that I can use something like:
$myParam = $item->getParams('theParamIwant');
Upvotes: 6
Views: 21686
Reputation: 1328
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'/>" : '';
Upvotes: 16
Reputation: 3790
Working in 3.5.1
$app = JFactory::getApplication();
$currentMenuId = JSite::getMenu()->getActive()->id;
$menuitem = $app->getMenu()->getItem($currentMenuId);
$params = $menuitem->params;
echo $params['menu_image'];
Shows menu item image
Upvotes: 0
Reputation: 63
($currentMenuId = JSite::getMenu()->getActive()->id ; // `enter code here`
$document =& JFactory::getDocument(); // `enter code here`
$app = JFactory::getApplication(); // `enter code here`
$menuitem = $app->getMenu()->getItem($currentMenuId); // or get item by ID `enter code here`
$params = $menuitem->params; // get the params `enter code here`
$params->get('menu-meta_keywords');
if($document->description == '') // 116 is the ID number of the menu pointing to the component `enter code here`
{
$this->setMetaData( 'description', $params->get('menu-meta_description') );
$this->setMetaData( 'keywords', $params->get('menu-meta_keywords') );
}
else
{
// do nothing
})
Upvotes: 0
Reputation: 42622
$app = JFactory::getApplication();
$params = $app->getParams();
$yourParameter = $params->get('YOURPARAMETERNAME');
Upvotes: 0
Reputation: 31
It doesn't work
Try to use this:
$params = $menus->getParams($menuId);
$myParam = $params->get('theParamIwant');
Upvotes: 3
Reputation: 1
JParameter is deprecated in Joomla 2.5, so to get Kevin's code to work add
jimport( 'joomla.html.parameter' )
before i.e
jimport( 'joomla.html.parameter' );
$item = $menu->getItem($menuId);
$params = new JParameter($item->params);
$myParam = $params->get('theParamIwant');
Upvotes: -1
Reputation: 96
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');
Upvotes: 8