Counting modules in a given module position: Difference between revisions

From Joomla! Documentation

MATsxm (talk | contribs)
m improve readability
Cmb (talk | contribs)
m Fixed the placement of <translate> elements.
Line 1: Line 1:
<noinclude><languages /></noinclude>
<noinclude><languages /></noinclude>
<translate>
 
<!--T:1-->
<translate><!--T:1-->
The <tt>countModules</tt> 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 <tt>countModules</tt> 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>
</translate>


<translate>
<translate><!--T:2-->
<!--T:2-->
For example, the following code includes modules in the 'user1' position only if at least one module is enabled for that position.
For example, the following code includes modules in the 'user1' position only if at least one module is enabled for that position.
</translate>  
</translate>  
Line 19: Line 18:


<noinclude>
<noinclude>
<translate>
<translate><!--T:3-->
<!--T:3-->
[[Category:Intermediate]]
[[Category:Intermediate]]
[[Category:Templates]]
[[Category:Templates]]

Revision as of 22:37, 5 July 2019

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; ?>