06 Killer Smarty Features You Need to Know

Smarty is by far my favorite PHP template engine. I’ll debate the pros and cons of using a template engine in another post, but I wanted to share some of the Smarty features that I didn’t know existed until I dug through the manual.

1. {cycle}

{cycle} is definitely my favorite Smarty command. You pass it a string of comma-separated values and it cycles through them. I mostly use this, as the manual demonstrates, for zebra striping tables or comments or any sort of list.

{section name=rows loop=$data}
<tr bgcolor="{cycle values="#eeeeee,#d0d0d0"}">
   <td>{$data[rows]}</td>
</tr>
{/section}

Continue Reading 6 Killer Smarty Features You Need to Know »