Smarty table is even odd

I am using PHP smarty templater. I need to create an even line selection. Please send me an example on how to do this.

Also I have a variable:

$smarty.foreach.product.index

      

+3


source to share


3 answers


For such a situation smarty has a method called {loop}

<table>
{foreach $products as $product}
<tr class="{cycle values="odd,even"}">
   <td>{$product.name}</td>
</tr>
{/foreach}
</table>

      

The result for this would be:



<table>
<tr class="odd">
   <td>1st product</td>
</tr>
<tr class="even">
   <td>2nd product</td>
</tr>
<tr class="odd">
   <td>3rd product</td>
</tr>
</table>

      

In your stylesheet, set properties for odd and even lines:

tr.even td{background: #CCCCCC;}
tr.odd td{background: #EFEFEF;}

      

+12


source


<table>
{foreach key=i item=row from=$items}
<tr{if $i%2==1} bgcolor=#e4e4e4{/if}><td>{$i}</td></tr>
{/foreach}
</table>

      



+2


source


{section name=myloop start=0 loop=10 step=1}
<tr class="{if $smarty.section.myloop.index is even}tr_even{else}tr_odd{/if}"><td>{$smarty.section.myloop.index}</td></tr>
{/section}

      

0


source







All Articles