什么是 Smarty?
为何使用 Smarty?
使用场景和工作流程
语法比较
模板继承
最佳实践
速成课程
{while}
循环在 Smarty 中与 PHP 的 while 语句拥有大致相同的灵活性并且添加了一些适用于模版引擎的新功能。每个 {while}
都必须与匹配的 {/while}
成对出现。所有 PHP 条件语句和函数都适用,如 ||、or、&&、and、is_array() 等。
以下是认可的一系列限定符,它们必须空格与周围元素分隔开。请注意,方括号中列出的项目是可选的。适用的情况下会显示 PHP 等价项。
限定符 | 交替符 | 语法示例 | 含义 | PHP 等价项 |
---|---|---|---|---|
== | eq | $a eq $b | equals | == |
!= | ne, neq | $a neq $b | not equals | != |
> | gt | $a gt $b | greater than | > |
< | lt | $a lt $b | less than | < |
>= | gte, ge | $a ge $b | greater than or equal | >= |
<= | lte, le | $a le $b | less than or equal | <= |
=== | $a === 0 | check for identity | === | |
! | not | not $a | negation (unary) | ! |
% | mod | $a mod $b | modulous | % |
is [not] div by | $a is not div by 4 | divisible by | $a % $b == 0 | |
is [not] even | $a is not even | [not] an even number (unary) | $a % 2 == 0 | |
is [not] even by | $a is not even by $b | grouping level [not] even | ($a / $b) % 2 == 0 | |
is [not] odd | $a is not odd | [not] an odd number (unary) | $a % 2 != 0 | |
is [not] odd by | $a is not odd by $b | [not] an odd grouping | ($a / $b) % 2 != 0 |