Bookmark and Share

Lee's 程序人生

HTML CSS Javascript XML AJAX ATLAS C# C++ 数据结构 软件工程 设计模式 asp.net Java 数字图象处理 Sql 数据库
  博客园  :: 首页  :: 新随笔  :: 联系 :: 管理

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

Posted on 2008-06-13 10:24  analyzer  阅读(1058)  评论(0)    收藏  举报
{if $smarty.section.outer.index is odd by 2}
test.tpl

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

test.php

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

{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

{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

{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