我有一个关于smarty模板的问题,我正在使用PHP和smarty来生成页面。我想以某种方式计算或确定表格的第一行和最后一行。所以我可以为第一个和最后一个TR设置不同的CSS,或者如果它只有1个TR,就保持原样
希望我追求的东西有意义。提前谢谢。
<table class="table-paddings-2" cellspacing="0" cellpadding="0">
<tr>
<th class="table-gray-th-noborder">Search Type</th>
<th class="table-gray-th-noborder">Average Turnaround Time</th>
</tr>
{foreach key=obk item=row from=$report}
<tr>
<td class="td-border-top-only text-align-left">{$row.SearchName}</td>
<td class="td-border-top-only text-align-left">{$row.tt}</td>
</tr>
{/foreach}
</table>
文档是您的朋友:http://www.smarty.net/docsv2/en/language.function.foreach.tpl
示例7.12、7.13:
{* show LATEST on the first item, otherwise the id *}
<table>
{foreach from=$items key=myId item=i name=foo}
<tr>
<td>{if $smarty.foreach.foo.first}LATEST{else}{$myId}{/if}</td>
<td>{$i.label}</td>
</tr>
{/foreach}
</table>