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
src/View/Planet/HtmlView.php
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
tmpl/planet/default.php
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
- menu-anchor_title
- menu-anchor_css
- menu_icon_css
- menu_image
- menu_image_css
- menu_text
- menu_show
- page_title
- show_page_heading
- page_heading
- pageclass_sfx
- menu-meta_description
- 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');