eq相等,smarty 比较操作符!时间戳

eq相等,
ne、neq不相等,
gt大于,
lt小于,
gte、ge大于等于,
lte、le 小于等于,
not非, mod求模。 
is [not] div by是否能被某数整除,
is [not] even是否为偶数,
$a is [not] even by $b即($a / $b) % 2 == 0,
is [not] odd是否为奇,
$a is not odd by $b即($a / $b) % 2 != 0 示例:
equal/ not equal/ greater than/ less than/ less than or equal/ great than or equal/后面的就不用说了
Smarty 中的 if 语句和 php 中的 if 语句一样灵活易用,并增加了几个特性以适宜模板引擎. if 必须于 /if 成对出现. 可以使用 else 和 elseif 子句. 可以使用以下条件修饰词:eq、ne、neq、gt、lt、lte、le、gte、ge、is even、is odd、is not even、is not odd、not、mod、div by、even by、odd by、==、!=、>、<、<=、>=. 使用这些修饰词时必须和变量或常量用空格格开.


Example 7-11. if statements
例 7-11. if 语句演示


{if $name eq "Fred"}
Welcome Sir.
{elseif $name eq "Wilma"}
Welcome Ma'am.
{else}
Welcome, whatever you are.
{/if}


{* an example with "or" logic *}
{if $name eq "Fred" or $name eq "Wilma"}
...
{/if}


{* same as above *}
{if $name == "Fred" || $name == "Wilma"}
...
{/if}


{* the following syntax will NOT work, conditional qualifiers
must be separated from surrounding elements by spaces *}
{if $name=="Fred" || $name=="Wilma"}
...
{/if}




{* parenthesis are allowed *}
{if ( $amount < 0 or $amount > 1000 ) and $volume >= #minVolAmt#}
...
{/if}


{* you can also embed php function calls *}
{if count($var) gt 0}
...
{/if}


{* test if values are even or odd *}
{if $var is even}
...
{/if}
{if $var is odd}
...
{/if}
{if $var is not odd}
...
{/if}


{* test if var is divisible by 4 *}
{if $var is div by 4}
...
{/if}


{* test if var is even, grouped by two. i.e.,
0=even, 1=even, 2=odd, 3=odd, 4=even, 5=even, etc. *}
{if $var is even by 2}
...
{/if}


{* 0=even, 1=even, 2=even, 3=odd, 4=odd, 5=odd, etc. *}
{if $var is even by 3}
...

{/if}

时间戳

而在smarty模板中,如$time是php文件中assign过来的时间戳,在模板文件中写法为:
<{$time|date_format:'%Y-%m-%d %H:%M:%S'}> ,同样对应的输出格式为:“年-月-日 时:分:秒”。

转载于:https://my.oschina.net/u/162418/blog/123049

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值