test.tpl


 

1{if $smarty.section.outer.index is odd by 2}_smarty<table border=1>
2{if $smarty.section.outer.index is odd by 2}_smarty{section name=outer loop=$FirstName}
3{if $smarty.section.outer.index is odd by 2}_smarty{if $smarty.section.outer.index is odd by 3}
4{if $smarty.section.outer.index is odd by 2}_smarty <tr bgcolor="#EFEFEF"><td>
5{if $smarty.section.outer.index is odd by 2}_smarty {$smarty.section.outer.index}-{$smarty.section.outer.rownum} . {$FirstName[outer]} {$LastName[outer]}
6{if $smarty.section.outer.index is odd by 2}_smarty </td></tr>
7{if $smarty.section.outer.index is odd by 2}_smarty{else}
8{if $smarty.section.outer.index is odd by 2}_smarty <tr bgcolor="#FFFFFFF"><td>
9{if $smarty.section.outer.index is odd by 2}_smarty {$smarty.section.outer.index}-{$smarty.section.outer.rownum} * {$FirstName[outer]} {$LastName[outer]}
10{if $smarty.section.outer.index is odd by 2}_smarty </td></tr>
11{if $smarty.section.outer.index is odd by 2}_smarty{/if}
12{if $smarty.section.outer.index is odd by 2}_smarty{sectionelse}
13{if $smarty.section.outer.index is odd by 2}_smarty none
14{if $smarty.section.outer.index is odd by 2}_smarty{/section}
15{if $smarty.section.outer.index is odd by 2}_smarty
16{if $smarty.section.outer.index is odd by 2}_smarty</table>


test.php

 

1{if $smarty.section.outer.index is odd by 2}_smarty<?php
2{if $smarty.section.outer.index is odd by 2}_smarty
3{if $smarty.section.outer.index is odd by 2}_smartyrequire 'lib/Smarty-2.6.11/libs/Smarty.class.php';
4{if $smarty.section.outer.index is odd by 2}_smarty
5{if $smarty.section.outer.index is odd by 2}_smarty$smarty = new Smarty;
6{if $smarty.section.outer.index is odd by 2}_smarty
7{if $smarty.section.outer.index is odd by 2}_smarty//$smarty->compile_check = true;
8{if $smarty.section.outer.index is odd by 2}_smarty//$smarty->debugging = true;
9{if $smarty.section.outer.index is odd by 2}_smarty
10{if $smarty.section.outer.index is odd by 2}_smarty//$smarty->assign("hello","byby");
11{if $smarty.section.outer.index is odd by 2}_smarty$smarty->assign("FirstName",array("John","Mary","James","Henry","Tom","Hello"));
12{if $smarty.section.outer.index is odd by 2}_smarty
13{if $smarty.section.outer.index is odd by 2}_smarty$smarty->display('test.tpl');
14{if $smarty.section.outer.index is odd by 2}_smarty
15{if $smarty.section.outer.index is odd by 2}_smarty?>

index
index用来显示当前循环的指针,从0开始.
index_prev
用来显示前一次循环的指针,从-1开始
index_next
用来显
示后一次循环的指针.

{if $smarty.section.outer.index is odd by 1}

0 -1 * John
1 -2 . Mary
2 -3 * James
3 -4 . Henry
4 -5 * Tom
5 -6 . Hello

0/1=0  非奇非偶,执行else项

1/1=1  奇数,执行if项

2/1=2  偶数,执行else项

3/1=3  奇数,执行if项

4/1=4 偶数,执行else项

5/1=5 奇数,执行if项


{if $smarty.section.outer.index is odd by 2}

0 -1 * John
1 -2 * Mary
2 -3 . James
3 -4 . Henry
4 -5 * Tom
5 -6 * Hello

0/2=0 非奇非偶,执行else项

1/2=0 非奇非偶,执行else项

2/2=1 奇数,执行if项

3/2=1 奇数,执行if项

4/2=2 偶数,执行else项

5/2=2 奇数,执行else项


{if $smarty.section.outer.index is odd by 3}

0 -1 * John
1 -2 * Mary
2 -3 * James
3 -4 . Henry
4 -5 . Tom
5 -6 . Hello

 

0/3=0 非奇非偶,执行else项

1/3=0 非奇非偶,执行else项

2/3=0  非奇非偶,执行else项

3/3=1 奇数,执行if项

4/3=1 奇数,执行if项

5/3=1 奇数,执行else项