Verge Studios Blog about Graphic Design, Web Design, and Joomla

Counting active Joomla modules

Frequently in Joomla we want to show different layouts depending on if there are modules active in certain module spaces. Joomla has (used to have) it's own solution by allowing you to define separate templates for internal pages and the home page. However this is very inconvenient as it means that you have to maintain several templates. There is however a simple solution to ascertaining if there are modules active in a module space, thus rendering different template elements. Insert the following inside your template:

<?php if ($this->countModules( 'leftcol' )) {?>
    // html code
<?php }?>

The above piece of code checks to see how many modules are inside a module space, in this case the 'leftcol'. If there are 0 modules, the above condition returns false and does not render what is in between the bracers. This would, for example, allow a div to expand into that space.

Comments

Write A Comment
 
Please input the anti-spam code that you can read in the image.