Saturday, 12 December 2015 19:33

How to style page according to menu

Written by
Rate this item
(0 votes)

There are times when we want to apply different styles to different Joomla pages based on menu. In this very short article I am going to show how to add classes to body tag. This is for Joomla, but it works for gantry framework too, you can see it on image above

 

It requires two short snipped of code injected into index.php inside your joomla template.

modification of index.php inside joomla template

All you need is add :

<?php $active=JFactory::getApplication()->getMenu()->getActive(); ?>

which takes active menu object (home, typogrphy, whatever...) and later render it into body class

<body class="<?php echo $active->alias;?>"

Next step is to add styles.

gantry custom css

It gives you great flexibility to your joomla design.

Read 880 times
More in this category: « Custom 404 error pages