計算模組位置多少模組使用

From Joomla! Documentation

Revision as of 06:14, 29 January 2021 by Shawnhy (talk | contribs) (Created page with "<tt>countModules</tt> method 可以在佈景主題中用來計算,有多少個啟用的模組用在這個位置。這可以用於模組相鄰的 HTML 程式碼,來知道...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Other languages:
Deutsch • ‎English • ‎Nederlands • ‎español • ‎français • ‎български • ‎русский • ‎中文(台灣)‎

countModules method 可以在佈景主題中用來計算,有多少個啟用的模組用在這個位置。這可以用於模組相鄰的 HTML 程式碼,來知道特定的模組位置至少有一個啟用中的模組。這會避免空白的範圍在佈景主題中被定義,此外這個技巧也常用於 “ 收摺欄”。

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

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