Home >Backend Development >PHP Tutorial >Smarty to realize alternate display of table colors_PHP tutorial
In the past, when SMARTY was not used, JQUERY was used to alternately display table colors. But now that SMARTY is used, it is very simple to implement this style. SMARTY provides a function: cycle. The following is the example code:
The final effect is as follows:
test.php>>>
< ;?php
include_once("smarty_inc.php");
$arr=array(a,b,c,d,e,f);
$smarty->assign(arr,$arr );
$smarty->display("test.tpl");
?>
test.tpl>>>
< table width="100px">
{section name=a loop=$arr} {cycle values="#eeeeee,#55eero"}"> ;
{$arr[a]}
{/section}
The above is the code, it is very convenient to use.