I am trying to make a joomla template. I am also using bootstrap v2.3.2. I want to make a design 3/12-6/12-3/12 distribution. I am checking if any modules are positioned on the left and right columns

$span = 12;

if ($this->countModules('right')) $span -= 3;
if ($this->countModules('left'))  $span -= 3;

<?php if ($this->countModules('left')): ?>
    <div id="sidebarleft" class="span3">
        <jdoc:include type="modules" name="left" style="well" />
<?php endif; ?>

<div id="content" class="<?php echo $span; ?>">
    <jdoc:include type="message" />
    <jdoc:include type="component" />

<?php if ($this->countModules('right')) : ?>
    <div id="sidebarright" class="span3">
        <jdoc:include type="modules" name="right" style="none" />
<?php endif; ?>

I have assigned a mod_articles_category module to left position but it is empty. So the module is not shown. But joomla thinks that there is a module in that position and it has to shrink content with.

How can I use the space if module is not shown on a page?

1 Answer 1


If I understood you right, this snippet should help (note, I haven't run the code)

if ($this->countModules('left')) {
   $modules = JModuleHelper::getModules('left');
   $modulesContent  = array();
   foreach ($modules as $module) {
      $content = JModuleHelper::renderModule($module, array('style' => 'well'));
      if(!empty($content)) {
         $modulesContent[] = $content;
<?php if(!empty($modulesContent)) : ?>
   <div id="sidebarleft" class="span3">
      <?php foreach ($modulesContent as $content) : ?>
        <?php echo $content; ?>
      <?php endforeach; ?>
<?php endif; ?>
  • To keep with the format of the original question, you would also then want to subtract 3 from $span in the bottom if statement (once we have shown that the modules have content) to adjust the width of the main column. Aug 19, 2014 at 21:06
  • Also note that this would think that the modules had content even if it just had an empty div tag in the module, so it may not help much more than countModules. Aug 19, 2014 at 21:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.