It is actually pretty simple to implement this. It only consists of using an if condition inside of your index.php file.
You probably know how to create a module position. You use the following syntax
<jdoc:include type="modules" name="sidebar" style="xhtml" />
This will create a sidebar module position. If you set the width of the sidebar to 200px, that 200px space will be there whether your module is enabled or not. To change this, we need to create an if statement and use the countModules function. All the countModules function does is return how many modules are enabled in a position. So what we want to do is create an IF statement asking if there are any modules enabled in this position. If not, then do not include the module posision code above. Here is an example
<?php if ($this->countModules( 'sidebar' )) : ?> <div class="right"> <jdoc:include type="modules" name="sidebar" style="xhtml" /> </div> <?php endif; ?>
If you have your module position wrapped in a div tag, make sure that you use the div tag inside of the IF statement. If not, the div properties will still be applied.
You can also include multiple module positions to use more advanced calculations.
<?php if ($this->countModules( 'user1 or user2' )) : ?> <div> <jdoc:include type="modules" name="user1" style="xhtml" /> <jdoc:include type="modules" name="user2" style="xhtml" /> </div> <?php endif; ?>
Operators for use with the countModules function
Here are the comparison and arithmetic operators that are available:






