php - Using "cycle" in smarty template system? -
here's current code:
{foreach from=$items item=item name=utable} {foreach from=$item.terms item=tmp name=titem} <tr class="{cycle values="odd,even"}"> removed unnecessary code here {/foreach} {/foreach}
the values odd
, even
rotating correctly tr
class.
however, rotation doesn't restart every new table. example, want first tr
of every table have class odd
, if lastly table ended odd
, next 1 keeps on starting even
.
is there way create cycle stop @ end of each table , restart @ next?
you need create utilize of reset
attribute print
.
sample php data:
$data = [1 => [2,3,51], 2 => [5,6,1], 4 => [1,2,21]]; $smarty->assign('tables',$data);
sample smarty file:
<style> tr.odd { background: red; } tr.even { background: #fff; } table { margin: 50px 0; } </style> {foreach $tables $table} {cycle values="" reset=true print=false} <table> {foreach $table $row} <tr class="{cycle values="odd,even"}"> <td> {$row} </td> {/foreach} </table> {/foreach}
as alternative can way:
{foreach $tables $table} <table> {foreach $table $row} {if $row@first}{assign var="reset" value=true}{/if} <tr class="{cycle values="odd,even" reset=$reset}"> <td> {$row} </td> {assign var="reset" value=false} {/foreach} </table> {/foreach}
php smarty
No comments:
Post a Comment