Difference between revisions of "Counting modules in a given module position"

From Joomla! Documentation

m (Fixed the placement of <translate> elements.)
(Some markup changes.)
 
(3 intermediate revisions by one other user not shown)
Line 2: Line 2:
  
 
<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 ''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>
 
</translate>
  
 
<translate><!--T:2-->
 
<translate><!--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 one or more modules are enabled for that position.
 
</translate>  
 
</translate>  
  
<source lang="php">
+
<syntaxhighlight lang="php">
 
<?php if ($this->countModules( 'user1' )) : ?>
 
<?php if ($this->countModules( 'user1' )) : ?>
 
   <div class="user1">
 
   <div class="user1">
Line 15: Line 15:
 
   </div>
 
   </div>
 
<?php endif; ?>
 
<?php endif; ?>
</source>
+
</syntaxhighlight>
  
 
<noinclude>
 
<noinclude>

Latest revision as of 16:27, 10 October 2022

Other languages:
Deutsch • ‎English • ‎Nederlands • ‎español • ‎français • ‎български • ‎русский • ‎中文(台灣)‎

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 one or more modules are enabled for that position.

<?php if ($this->countModules( 'user1' )) : ?>
  <div class="user1">
    <jdoc:include type="modules" name="user1" style="rounded" />
  </div>
<?php endif; ?>