Search
Other ReReplacer questions
Forum

Issues adding page class to body tag

Vincent Mross's Avatar Vincent Mross
I like to add a body class to all of my template installations because it makes styling individual pages very easy. Adding a page class to a menu item doesn't always do the trick, because it only affects the component area of the page. Here is how I do it in Joomla 4/5:

Add this to the head area:
<?php
  $app = JFactory::getApplication();
  $menu = $app->getMenu()->getActive();
  $pageclass = '';

  if (is_object($menu))
     $pageclass = $menu->getParams()->get('pageclass_sfx');
?>

[b]And this to the body area:[/b]

[code]<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.

The problem I am having is that the Samba Spa template overrides the body class in mobile view, rendering it like this:
<body id="s5_body" class="s5_responsive_mobile_present">

I made a post in the Joomla forums about this issue here:
forum.joomla.org/viewtopic.php?f=808&t=1009296

In that thread, Pavel-ww mentions that the problem with Body classes comes from this file "s5_responsive_mobile_bar-min.js" The logic of the script should be rewritten so that it does not replace the classes, but adds to the existing ones.

What I have tried with ReReplacer (I bought the pro version so that I could target only the home page by using conditions) is this:

Search:
class="s5_responsive_mobile_present"
Replace:
class="s5_responsive_mobile_present home homie"

I have tried with and without regular expressions, but no luck.

But apparently the file "s5_responsive_mobile_bar-min.js" overwrites whatever is outputted by ReReplacer. How can I get around this? Here is the website by the way:

feminapt.com/
Peter van Westen's Avatar Peter van Westen ADMIN
ReReplacer works on the php level. It replaces stuff in the output html of your page.

Stuff added via a js file are done client side. That is not something ReReplacer can see, as it happens after the page is rendered on the server.

In other words: no, you can't use ReReplacer to replace things that have been added to the DOM via javascript.
Please post a rating at the Joomla! Extensions Directory
Vincent Mross's Avatar Vincent Mross
Well crap. Thanks for the reply anyhow.
Peter van Westen's Avatar Peter van Westen ADMIN
If you need a refund for the ReReplacer subscription, let me know...
Please post a rating at the Joomla! Extensions Directory
Vincent Mross's Avatar Vincent Mross
I have a lot of websites that I could use the Pro version on, so let me think about that and thanks for the offer!
You can only post on the extension support forum if you have an active subscription and you log in

Buy a Pro subscription