这是我用来计算 joomla 中的模块的代码,以查看它是否可用。
<?php if ($this->countModules( 'right' )) : ?>
现在我想要与此相反的情况,例如,当未设置模块时..
我应该使用类似的东西:
<?php if (!$this->countModules( 'right' )) : ?>
我的意思是,我应该使用什么来实现它?我想,不是假设,但我写的方式肯定是错误的。
<?php if ($this->countModules( 'right' )) : ?>
检查true
它的反面是这个
<?php if (!$this->countModules( 'right' )) : ?>
它检查false
你可以这样做:
if ($this->countModules( 'right' ) <= 0) :
或者这个(更易读的恕我直言):
if ( empty($this->countModules( 'right' )) ) :
顺便说一下,countModules()
只返回在该模块位置启用的模块数量,因此如果返回值为 0,则表示没有启用任何模块。
这应该这样做:
<?php
if( $this->countModules( 'right' ) < 1 ) : echo 'No right modules'; endif;
?>
“!” 代表假,它是一个布尔值。“< 1”表示实数,换句话说,表示小于 1 的任何值。如果您使用 Joomla 的“countModules”功能,我们正在计算模块,因此使用数字比较是有意义的。
<?php
if ($this->countModules( 'right' )) :
//there are modules
else :
//no modules
endif;
?>