joomla 模块位置 if else and

joomla module position if else and

我正在创建一个响应式模板,为此我需要使用 if else 和函数。这是我目前所拥有的。

<?php if ($this->countModules('left')) { ?>
<p>Left + Content</p>
<?php } elseif ($this->countModules('right')) { ?>
<p>Right + Content</p>
<?php } elseif ($this->countModules('left')) && ($this->countModules('right')) { ?>
<p>Left + Right + Content</p>
<?php } else { ?>
<p>Content</p>
<?php } ?>

我现在收到错误: 解析错误:语法错误,第 197 行 index.php 中的意外 '&&' (T_BOOLEAN_AND)

第 197 行 =

<?php } elseif ($this->countModules('left')) && ($this->countModules('right')) { ?>

我尝试添加一个额外的 () 但没有成功:

<?php } elseif (($this->countModules('left')) && ($this->countModules('right'))) { ?>

我忘记了一些东西。

你的括号放错地方了。尝试替换以下内容:

<?php } elseif ($this->countModules('left')) && ($this->countModules('right')) { ?>

有了这个:

<?php } elseif ($this->countModules('left') && $this->countModules('right')) { ?>

顺序错误,您应该删除一组,而不是添加 ()。请参阅下面的改编代码。

<?php if ($this->countModules('left') && $this->countModules('right')) { ?>
<p>Left + Right + Content</p>
<?php } elseif ($this->countModules('right')) { ?>
<p>Right + Content</p>
<?php } elseif ($this->countModules('left')) { ?>
<p>Left + Content</p>
<?php } else { ?>
<p>Content</p>
<?php } ?>

希望这能让你走对路。