Assuming you are modifying the mod_menu's default.php template, then to access the "Link CSS Style" param, all you need is
But the above answer would be valid only for the mod_menu and only in the context of:
$list = ModMenuHelper::getList($params);
foreach ($list as $i => &$item)
$class = $item->anchor_css;
Update following the dialogue in the comments section:
Jakub Skowroński:: I building separate menu module. I tried your method but I cant get the class.
FFrewin:: Of course you can't get the class if you are in a module of yours and you haven't created such class.
FFrewin:: The module you are creating, what will do that will be different from the mod_menu ?
Jakub Skowroński:: Different function and styling. Is it really so hard to get this one param to other module?
FFrewin:: It's no hard at all. But php variables get their meaning when used inside a specific context. In your code you are using an
$item which seems to be an object from the way you use it. However, what object is this, is not possible to know from the code you have presented. Therefore we can't know what properties or methods this object may have.
I asked for what your module will do differently than the mod_menu, because the code seems to be similar to the mod_menu, and I am not sure if you really need to create a new module, or simply create a template override for the mod_menu, where you can easily use the
$list array of
$item objects (generated by the
ModMenuHelper::getList(), to access each
$item object's properties.
Whatever the case, you can study the
ModMenuHelper::getList($params) method, to see how it returns the
$list array that is populated with the menu items and their properties as objects, of a specific menu that is passed as an argument and has been previously selected in the backend of the module. Then you can modify it to suit your needs inside your helper.php file.
Below as a short snippet, similar to the one inside the mod_menu helper file. which is addressing how to access the css anchor property of menu items, this snippet example may help:
$app = JFactory::getApplication();
$menu = $app->getMenu();
$items = $menu->getItems('menutype', 'mainmenu');
foreach ($items as $i => $item)
$item->anchor_css = htmlspecialchars($item->params->get('menu-anchor_css', ''), ENT_COMPAT, 'UTF-8', false);
//Above we are assigning the anchor_css protected property, to another object property 'anchor_css' for easy access.
echo "<pre>" . print_r($items, true)."</pre>";
Documentation: JMENU SITE API