How to Access Joomla Menu Parameters for Component

When you create a menu item for any view of the component, there are many options in the menu you can configure. These values can be accessed in Joomla! code.

Step 1: View File


First, get all the current menu parameters,

$app = Factory::getApplication();
$active = $app->getMenu()->getActive();
$this->params = $active->getParams();

Now, you can access any individual parameter.

$show_title = $this->params->get('show_title', 1);

The $active is object that contains information about the active or current menu. For example: id, menutype, title, alias, route, link, type, level. You can access these like $active->id or $active->title.

Step 2: Layout File


You can also access the parameters in the layout file. For example, first get the menu parameter.

$show_title = $this->params->get('show_title', 1);

Then, use it to show or hide the title.

<?php if ($show_title) : ?>
    <h1><?php echo $this->item->title; ?></h1>
<?php endif; ?>

To define any parameter:

$this->params->def('page_heading', $this->params->get('page_title', $active->title));

Standard Parameters

  1. menu-anchor_title
  2. menu-anchor_css
  3. menu_icon_css
  4. menu_image
  5. menu_image_css
  6. menu_text
  7. menu_show
  8. page_title
  9. show_page_heading
  10. page_heading
  11. pageclass_sfx
  12. menu-meta_description
  13. robots

To access Menu parameters from a known Itemid:

$app = Factory::getApplication();
$input = $app->input;
$itemId = $input->get('Itemid', '0', 'INT');
$menuItem = $app->getMenu()->getItem($itemId);
$params = $menuItem->getParams();
$yourParameter = $params->get('yourParameter');