我在Joomla模板中找到了一个小脚本,用来检查当前页面上是否有一个模块分配给了特定的模块位置。
<?php
$attribs['style'] = 'xhtml';
$modules_html = '';
foreach (JModuleHelper::getModules( 'module_position' ) as $module)
$modules_html .= JModuleHelper::renderModule( $module, $attribs );
$show_module=trim($modules_html) != '';
if ($show_module) {
?>
<jdoc:include type="modules" name="module_position" style="xhtml" />
<?php } ?>
该脚本运行良好,但与模块包装器div和标题重复,因此输出通常如下所示:
<div class="moduletable">
<h3>Module Title</h3>
<div class="moduletable">
<h3>Module Title</h3>
<p>Content here</p>
</div>
</div>
我想去掉重复的包装和标题,但我一辈子都不知道该怎么做。
建议将是最受欢迎的。
干杯!
您将jdoc标记放入循环中,这样,如果在同一位置发布了多个模块,它就会重复。
你只需要拥有一次。您也可以使用joomla的countModules函数。请参阅此处http://docs.joomla.org/JDocumentHTML/countModules