我找到了一个我在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>
我想摆脱重复的包装和标题,但无法弄清楚我的生活怎么做。
建议非常欢迎。
干杯!
答案 0 :(得分:0)
你将jdoc标记放在循环中,这样如果你在同一个位置上发布了多个模块,它就会重复出现。
你只需要一次。 你也可以使用joomla的countModules函数。见http://docs.joomla.org/JDocumentHTML/countModules