I want to add the alias to the body. I don't want to edit my template in case of template updates. So I'm going to create a plugin to overcome this issue.
So my query is... can I do this in PHP or should I just use jQuery. I know I need PHP to get the alias, and using jQuery is fine to add the class.
I'm just wondering which is the best way or if there is any downside.
So far I've come up with this but for some reason it is not working. The PHP part works but not the JavaScript
<?php
$app = JFactory::getApplication();
$menu = $app->getMenu();
$active = $menu->getActive();
$alias = $active->alias;
$javascript='
document.body.classList.add("' . $alias . '");
';
$document=JFactory::getDocument();
$document->addScriptDeclaration($javascript);
?>