example usage of cycle

From: Date: Fri, 03 May 2002 16:04:24 +0000
Subject: example usage of cycle
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-4036@lists.php.net to get a copy of this message
Here are some examples of using cycle. To alternate row colors: {section ...} <tr bgcolor="{cycle values="#eeeeee,#dddddd"}">
      ...
</tr> {/section} To alternate column colors: {section ...} <tr>
      <td bgcolor="{cycle values="#eeeeee,#dddddd"}"> ... </td>
      <td bgcolor="{cycle}"> ... </td>
      <td bgcolor="{cycle}"> ... </td>
      ...
      <td bgcolor="{cycle advance=false}"> ... </td>
</tr> {/section} (you may need the advance=false on the last column depending on the # of columns and if you want a checker board pattern or not) Now a trickier one, cycling through four colors on columns, two on the even rows and two on the odd rows. {* setup the cycles *} {cycle id=0 values="#eeeeee,#dddddd" reset=true print=false} {cycle id=1 values="#eeeeee,#dddddd" reset=true print=false} {section name=foo ...} {if $smarty.section.foo.index is even}
      {assign var="cycle_id" value=0}
{else}
      {assign var="cycle_id" value=1}
{/if} <tr>
      <td bgcolor="{cycle id=$cycle_id}"> ... </td>
      <td bgcolor="{cycle id=$cycle_id}"> ... </td>
      <td bgcolor="{cycle id=$cycle_id}"> ... </td>
      ...
      <td bgcolor="{cycle id=$cycle_id advance=false}"> ... </td>
</tr> {/section} -- Monte Ohrt <monte@ispi.net> Director of Technology, ispi Inc.

« previous php.smarty.general (#4036) next »