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

From Joomla! Documentation

m
m (improve readability)
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<includeonly>== Counting Modules in a given Module position ==</includeonly>
+
<noinclude><languages /></noinclude>
The countModules function can be used within a template to determine the number of Modules enabled in a given Module position.  This is commonly used to include 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.
+
<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”.
 +
</translate>
  
For example, the following code includes Modules in the 'user1' position only if at least one Module is enabled for that position.
+
<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.
 +
</translate>
  
 
<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>
 
<noinclude>
 +
<translate>
 +
<!--T:3-->
 
[[Category:Intermediate]]
 
[[Category:Intermediate]]
 
[[Category:Templates]]
 
[[Category:Templates]]
 
[[Category:Topics]]
 
[[Category:Topics]]
 +
[[Category:Tutorials]]
 +
[[Category:Template Development]]
 +
</translate>
 
</noinclude>
 
</noinclude>

Revision as of 09:26, 26 May 2015

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