joomla 上的高级条件模块位置

发布于 2024-11-24 01:46:54 字数 1438 浏览 4 评论 0原文

我有一个盒子,里面包含三个模块位置。现在的目标是当一个模块位置单独加载时,它的宽度应该是盒子的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; ?>


more explain:

我想定义每个特殊条件,但这样我不知道如何比较“三个”(或更多)位置。即我知道当我想“仅显示两个位置之一(而不是两个位置)”时,我应该使用这个:

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

但是如果我想同时将一个位置与其他两个位置进行比较;代码是什么?类似的东西:?

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

在上面的代码中,我想显示user1或 user2或user3位置之一。这是真的吗?

谢谢

I have a box which contains three module positions inside.Now the target is when a module position loaded alone, its width should be 100% of the box; when two of the modules positions loaded, the width of each one should be 50%; and finally when all three positions loaded, apiece should be 33%.
How could I set this conditions with the least coding?
my code is now something like this:

<?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; ?>


more explain:

I think to define every special condition but in this way I don't know how to compare "three" (or more) positions with each other. i.e I know when I want to ِ Display just one of two positions (and not both of them), I should use this:

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

But if I wanna compare one position with two other positions at the same time; What will be the code? somethings similar this: ?

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

in above code I want to show just user1 or only one of user2 or user3 positions. Is it true?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烧了回忆取暖 2024-12-01 01:46:54

它比这简单得多:暂时忘记 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。

It's much simpler than that: for a second, forget about the joomla-countModules-funkyness. Then you can get the number of Modules rather quickly:

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

Converting the coutModules-Return to a boolean is a shortcut for $this->countModules( 'user1' ) ? 1 : 0.

南巷近海 2024-12-01 01:46:54

此外,这应该可以通过纯 HTML/CSS 实现。我记得如果你制作一个列大小为“100%”且宽度固定的表格,浏览器会自动缩放它以符合列数:

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

我怀疑这是否符合 HTML 标准,但......

Also, this should be possible with plain HTML/CSS. I recall that if you make a table with column size "100%" and fixed width, the browser scales it automatically to comply with the number of columns:

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

I doubt this is HTML-Standard-Compliant, though ...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文