}
<tr bgcolor="{cycle values="#D4D0C8,#EEEEEE"}">
<td>{$data[rows]}</td>
</tr>
{/section}
---------------------------------------------------------------------------------
例5: 使用模板内置流程控制语句进行一行多单元格内容输出, 也就是在视觉上smarty每记输出几条记录:
================================================
example5.tpl
================================================
<html>
<head><title>一行输出多条记录</title></head>
<body>
<table>
<tr>
{section name=loop loop=$News step=1}
{if $smarty.section.loop.index % 4 == 0}
</tr>
<tr>
{/if}
<td>{$News[loop].newsID}</td>
<td>{$News[loop].newsTitle}</td>
{/section}
</tr>
</table>
</body>
</html>
====================================================
example5.php
====================================================
<?php
/*********************************************
*
* 文件名: example5.php
* 作 用: 显示实例程序5
*
* 作 者: 大师兄
* Email:teacherli@163.com
*
*********************************************/
require_once ("./comm/Smarty.class.php");
$smarty = new Smarty();
$smarty->template_dir = ''''./templates/'''';
$smarty->compile_dir = ''''./templates_c/'''';
$smarty->config_dir = ''''./configs/'''';
$smarty->cache_dir = ''''./cache/'''';
$smarty->caching = false;
$array[]= array("newsID"=>"001", "newsTitle"=>"第1条新闻");
$array[]= array("newsID"=>"002", "newsTitle"=>"第2条新闻");
$array[]= array("newsID"=>"003", "newsTitle"=>"第3条新闻");
$array[]= array("newsID"=>"004", "newsTitle"=>"第4条新闻");
$array[]= array("newsID"=>"005", "newsTitle"=>"第5条新闻");
$array[]= array("newsID"=>"006", "newsTitle"=>"第6条新闻");
$array[]= array("newsID"=>"007", "newsTitle"=>"第7条新闻");
$array[]= array("newsID"=>"008", "newsTitle"=>"第8条新闻");
$smarty->assign("News", $array);
$smarty->display("example5.tpl");
?>
==================================================
example5.php输出内容:
==================================================
<html>
<head><title>一行输出多条记录</title></head>
<body>
<table>
<tr>
</tr>
<tr>
<td>001</td>
<td>第1条新闻</td>
<td>002</td>
<td>第2条新闻</td>
<td>003</td>
<td>第3条新闻</td>
<td>004</td>
<td>第4条新闻</td>
</tr>
<tr>
<td>005</td>
<td>第5条新闻</td>
<td>006</td>
<td>第6条新闻</td>
<td>007
|