EZ Publish/EZ Publish 模板控制结构
来自站长百科
EZ Publish | EZ Publish安装与卸载 | EZ Publish的使用 | EZ Publish常见问题 | EZ Publish其他 |
eZ Publish 模板语言提供了以下的控制结构:
• IF-THEN-ELSE
• SWITCH
• WHILE
• DO...WHILE
• FOR
• FOREACH
IF-THEN-ELSE[ ]
参阅下例:
例1:
{if eq( $var, 128 )} Hello world <br /> {else} No world here, move along. <br /> {/if}
例2:
{if eq( $fruit, 'apples' )} Apples {elseif eq( $fruit, 'oranges' )} Oranges {else} Bananas {/if}
SWITCH[ ]
{switch match=$fruits} {case match='apples'} Apples {/case} {case match='oranges'} Oranges {/case} {case} Unidentified fruit! {/case} {/switch}
如果$fruits 初始值为'oranges',则输出:
Oranges
WHILE[ ]
{while ne( $counter, 8 )} Print this line eight times ({$counter}) <br /> {set $counter=inc( $counter )} {/while}
如果$counter 初始值为0,则输出:
Print this line eight times (0) Print this line eight times (1) Print this line eight times (2) Print this line eight times (3) Print this line eight times (4) Print this line eight times (5) Print this line eight times (6) Print this line eight times (7)
DO...WHILE[ ]
{do} Keep printing this line ({$counter}) <br /> {set $counter=inc( $counter )} {/do while ne( $counter, 8 )}
如果$counter 初始值为0,则输出:
Keep printing this line (0) Keep printing this line (1) Keep printing this line (2) Keep printing this line (3) Keep printing this line (4) Keep printing this line (5) Keep printing this line (6) Keep printing this line (7) Keep printing this line (8)
FOR[ ]
{for 0 to 7 as $counter} Value of counter: {$counter} <br /> {/for}
输出:
Value of counter: 0 Value of counter: 1 Value of counter: 2 Value of counter: 3 Value of counter: 4 Value of counter: 5 Value of counter: 6 Value of counter: 7
FOREACH[ ]
{foreach $objects as $object} {$object.name} {/foreach}
如果$objects 是一个数组,且包含4 个对象,对象名依次为:"Emmett Brown","Marty McFly","Lorraine Baines"和"Biff Tannen",则输出:
Emmett Brown Marty McFly Lorraine Baines Biff Tannen