joomla上的高级条件模块位置


Advanced conditional module positions on joomla

我有一个包含三个模块位置的框。现在的目标是当一个模块位置单独加载时,它的宽度应该是框的100%;当两个模块位置加载时,每个模块的宽度应为50%;最后三个仓位都装好了,每个仓位应该是33%我怎样才能用最少的代码设置这些条件?我的代码现在是这样的:

<?php if ($this->countModules( 'user1 or user2 or user3' )) : ?>
<div style="width:860px; margin:10px auto;">
<?php if ($this->countModules( 'user3' )) : ?>
   <div style="width:33%; float:left; min-height:100px;"><jdoc:include type="modules" name="user3" style="xhtml" /></div>
<?php endif; ?> 
<?php if ($this->countModules( 'user2' )) : ?>
   <div style="width:34%; float:left; min-height:100px;"><jdoc:include type="modules" name="user2" style="xhtml" /></div>
<?php endif; ?> 
<?php if ($this->countModules( 'user1' )) : ?>
   <div style="width:33%; float:left; min-height:100px;"><jdoc:include type="modules" name="user1" style="xhtml" /></div>
<?php endif; ?>
</div>
<?php endif; ?>


更多的解释:

我想定义每个特殊条件,但这样我不知道如何比较"三个"(或更多)位置。也就是说,我知道当我想只显示两个位置中的一个(而不是两个)时,我应该使用这个:

<?php if ($this->countModules( 'user1 xor user2' )) : ?>>

但是如果我想将一个位置与同时比较另外两个位置;代码是什么??

<?php if ($this->countModules( 'user1 xor user2 or user3' )) : ?>
在上面的代码

中,我想显示 user1或 user2或user3位置中的一个。这是真的吗?

谢谢

实际情况要简单得多:暂时忘记joomla-countModules-funkyness。然后您可以很快地获得模块的数量:

$nbColumns = (bool) $this->countModules( 'user1' ) + (bool) $this->countModules( 'user2' ) + (bool) $this->countModules( 'user3' );
$widthColumn = 100.0 / $nbColumns;

将coutModules-Return转换为布尔值是$this->countModules( 'user1' ) ? 1 : 0的快捷方式。

同样,这应该可以使用纯HTML/CSS。我记得,如果你制作一个列大小为"100%"和固定宽度的表,浏览器会自动缩放它以符合列的数量:

<table style="width:400px;">
 <tr>
   <td width="100%">
     cell 1
   </td>
   <td width="100%">
    cell2
   </td>
  </tr>
</table>