# How to distribute width in according to module count?

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" />
</div>
<?php endif; ?>

<div id="content" class="<?php echo $span; ?>"> <jdoc:include type="message" /> <jdoc:include type="component" /> </div> <?php if ($this->countModules('right')) : ?>
<div id="sidebarright" class="span3">
<jdoc:include type="modules" name="right" style="none" />
</div>
<?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?

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

<?php
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; ?>
</div>
<?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. – David Fritsch Aug 19 '14 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. – David Fritsch Aug 19 '14 at 21:07