smarty 操作符号,大于、小于。。。

eq相等,6 w% x7 w6 |3 _
ne、neq不相等,( i" }" ~( `# V( t& C, k; [
gt大于,
lt小于,
gte、ge大于等于,
lte、le 小于等于,
not非, mod求模。
is [not] div by是否能被某数整除,( y3 R( Q4 t. k9 U; @# c0 X/ T
is [not] even是否为偶数,+ m! H, H4 i" G
$a is [not] even by $b即($a / $b) % 2 == 0,
is [not] odd是否为奇,; e. `2 \$ \# J/ P$ @# }
$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.! X) m' X1 Q% t% [$ g' M
{elseif $name eq "Wilma"}
Welcome Ma'am.
{else}4 y. |, R1 F4 Z: |4 ^  x6 |
Welcome, whatever you are.
{/if}

{* an example with "or" logic *}3 y; o; c1 i- j
{if $name eq "Fred" or $name eq "Wilma"}
...
{/if}

{* same as above *}( i# w! y# t; N  f
{if $name == "Fred" || $name == "Wilma"}
...
{/if}

{* the following syntax will NOT work, conditional qualifiers) L4 V( b" _( m/ U
must be separated from surrounding elements by spaces *}: I0 S, ~4 g7 [8 h% W8 p  Y5 v
{if $name=="Fred" || $name=="Wilma"}) p( S: y& T6 Q, z4 Z+ Q
...
{/if}

{* parenthesis are allowed *}+ w. K8 e9 ]$ T. ]# E
{if ( $amount < 0 or $amount > 1000 ) and $volume >= #minVolAmt#}" R$ Q/ c# p' [1 l  J$ i. a3 d
...3 `2 P8 A: m9 C! |
{/if}

{* you can also embed php function calls *}+ A' Q+ |8 F$ Z3 v1 B5 u1 o
{if count($var) gt 0}8 S; [; p1 L( {, R6 @$ d
...6 A7 z* v9 _1 _* Q4 U
{/if}

{* test if values are even or odd *}
{if $var is even}
...
{/if}9 K: @( K) A; B2 i1 ^5 |' E2 l
{if $var is odd}0 f1 y+ k$ e9 y8 a
...
{/if}- e+ p" d7 Q+ N6 t
{if $var is not odd}9 p! a% p& u5 L7 n1 ?5 g. T
...
{/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.,: Z* m  ~5 r; _0 _6 S
0=even, 1=even, 2=odd, 3=odd, 4=even, 5=even, etc. *}
{if $var is even by 2}. g" E, ]7 x' I3 B
...8 |; o( L9 `6 y( @& q7 s/ Q
{/if}

{* 0=even, 1=even, 2=even, 3=odd, 4=odd, 5=odd, etc. *}
{if $var is even by 3}4 M& W$ P, R. n; b  g. }% w4 _5 L
...
{/if}

上一篇:批量屏蔽符合条件的IP地址《目前仅测Centos 6 版本》


下一篇:最大子段和(Max Sum)