smarty问题

来源:百度知道 编辑:UC知道 时间:2024/05/22 08:52:40
如何用html_table输出二维数组里的内容
我尝试了一下没有成功,下面是我写的一段代码
<{section name=sec1 loop=$array2}>
<{html_table table_attr='border="0"' loop=$array2[sec1][]}>
<{/section}>

自定义函数 html_table 将数组中的数据填充到 HTML 表格中. cols 属性决定表格有多少列. table_attr , tr_attr 和 td_attr 属性决定表格中 tr 和 td 标签的一些附加属性. 如果 tr_attr 和 td_attr 属性值为数组,将轮流使用其中的值. 如果指定了 trailpad 属性,将在表尾最后一行附加一些数据.

例 函数演示

index.php:

require('Smarty.class.php');
$smarty = new Smarty;
$smarty->assign('data',array(1,2,3,4,5,6,7,8,9));
$smarty->assign('tr',array('bgcolor="#eeeeee"','bgcolor="#dddddd"'));
$smarty->display('index.tpl');

index.tpl:

{html_table loop=$data}
{html_table loop=$data cols=4 table_attr='border="0"'}
{html_table loop=$data cols=4 tr_attr=$tr}

OUTPUT:

<table border="1">
<tr><td>1</td><td>2</td><td>3</td></tr>
<tr><td>4</td><td>5</td><td>6</td></tr>
<tr><td>7