Counting modules in a given module position
From Joomla! Documentation
(Difference between revisions)
Mike dowler (Talk | contribs) m |
|||
| (2 intermediate revisions by one user not shown) | |||
| Line 1: | Line 1: | ||
| − | + | The countModules method can be used within a template to determine the number of modules enabled in a given module position. This is commonly used to include HTML around modules in a certain position only if at least one module is enabled for that position. This prevents empty regions from being defined in the template output and is a technique sometimes referred to as “collapsing columns”. | |
| − | The countModules | + | |
| − | For example, the following code includes | + | For example, the following code includes modules in the 'user1' position only if at least one module is enabled for that position. |
<source lang="php"> | <source lang="php"> | ||
<?php if ($this->countModules( 'user1' )) : ?> | <?php if ($this->countModules( 'user1' )) : ?> | ||
| − | <jdoc:include type="modules" name="user1" style="rounded" /> | + | <div class="user1"> |
| + | <jdoc:include type="modules" name="user1" style="rounded" /> | ||
| + | </div> | ||
<?php endif; ?> | <?php endif; ?> | ||
</source> | </source> | ||
| − | + | <noinclude>[[Category:Intermediate]][[Category:Templates]][[Category:Topics]]</noinclude> | |
| − | <noinclude> | + | [[Category:Tutorials]][[Category:Template Development]] |
| − | [[Category:Intermediate]] | + | |
| − | [[Category:Templates]] | + | |
| − | [[Category:Topics]] | + | |
| − | </noinclude> | + | |
Latest revision as of 07:47, 20 September 2010
The countModules method can be used within a template to determine the number of modules enabled in a given module position. This is commonly used to include HTML around modules in a certain position only if at least one module is enabled for that position. This prevents empty regions from being defined in the template output and is a technique sometimes referred to as “collapsing columns”.
For example, the following code includes modules in the 'user1' position only if at least one module is enabled for that position.
<?php if ($this->countModules( 'user1' )) : ?> <div class="user1"> <jdoc:include type="modules" name="user1" style="rounded" /> </div> <?php endif; ?>