I used to be able to modify any J3 template with this code to add a body class to the template:
Having a unique body class on each page is extremely useful. I've done some searching but come up dry with a solution for J4/5. Using the above code in J4 throws this error:
Anyone got a fix for this? Sorry for my lack of knowledge of PHP and Javascript, I'm just a lowly html/css geek! ;-)
Code:
First add this code above the doctype:<?php $app = JFactory::getApplication(); $menu = $app->getMenu()->getActive(); $pageclass = ''; if (is_object($menu)) $pageclass = $menu->params->get('pageclass_sfx');?>(Many templates have a place to add head code via the Joomla admin)And this code to your body:<body class="<?php echo $pageclass ? htmlspecialchars($pageclass) : 'default'; ?>">Anything without a page class will use a class of "default", anything with the page class defined will appear as the class entered into “Page Class” in the Menu Manager.
Code:
0 - Cannot access protected property Joomla\CMS\Menu\MenuItem::$params
Statistics: Posted by vincebodie — Mon May 20, 2024 7:55 pm