Counting modules in a given module position/zh-tw: Difference between revisions

From Joomla! Documentation

Created page with "例如,以下的程式碼會計算 <code>user1</code> 模組位置"
Line 14: Line 14:


<noinclude>
<noinclude>
[[Category:Intermediate]]
[[Category:Intermediate/zh-tw]]
[[Category:Templates]]
[[Category:Templates/zh-tw]]
[[Category:Topics]]
[[Category:Topics/zh-tw]]
[[Category:Tutorials]]
[[Category:Tutorials/zh-tw]]
[[Category:Template Development]]
[[Category:Template Development/zh-tw]]
</noinclude>
</noinclude>

Revision as of 06:08, 29 January 2021

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”.

例如,以下的程式碼會計算 user1 模組位置

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