Counting modules in a given module position: Difference between revisions
From Joomla! Documentation
No edit summary |
m Marked for translation |
||
| Line 1: | Line 1: | ||
<noinclude><languages /></noinclude> | |||
<translate> | |||
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 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”. | ||
</translate> | |||
For example, the following code includes modules in the 'user1' position only if at least one module is enabled for that position. | <translate> | ||
For example, the following code includes modules in the 'user1' position only if at least one module is enabled for that position. | |||
</translate> | |||
<source lang="php"> | <source lang="php"> | ||
| Line 10: | Line 15: | ||
<?php endif; ?> | <?php endif; ?> | ||
</source> | </source> | ||
<noinclude>[[Category:Intermediate]][[Category:Templates]][[Category:Topics]] | |||
[[Category:Tutorials]][[Category:Template Development]] | <noinclude> | ||
<translate> | |||
[[Category:Intermediate]] | |||
[[Category:Templates]] | |||
[[Category:Topics]] | |||
[[Category:Tutorials]] | |||
[[Category:Template Development]] | |||
</translate> | |||
</noinclude> | |||
Revision as of 14:51, 21 May 2015
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; ?>