Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Smarty table even odd

Tags:

php

smarty

I'm is using PHP smarty templater. I need to create even odd row highlighting. Please, send me example how to do that.

also I have variable:

$smarty.foreach.product.index
like image 645
xercool Avatar asked Dec 04 '22 00:12

xercool


1 Answers

For this kind of situation smarty has method called {cycle}

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

The result for this will 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 you stylesheet file define properties for odd and even lines like this:

tr.even td{background: #CCCCCC;}
tr.odd td{background: #EFEFEF;}
like image 88
Silvanu Avatar answered Dec 11 '22 12:12

Silvanu