Dynamic Table With Smarty Engine Template
February 1st, 2010
No comments
Usually I make a dynamic table using PHP, but because it turned out that I handled the project requires use Smarty as template engine, then finally a direct table generated by Smarty. So PHP is only to issue a query from the database.
Here is the template used to create a dynamic table on Smarty.
<table>
<tr>
{assign var=\"numCols\" value=\"6\"}
{assign var=\"col\" value=\"0\"}
{section name=element loop=$data}
{if $col == $numCols}
</tr><tr>{assign var=\"col\" value=\"0\"}
{/if}
<td>{$data[element]}
</td> {assign var=\"col\" value=\"`$col+1`\"}
{/section}
{assign var=\"remainder\" value=\"`$numCols-$col`\"}
{section name=emptyElement loop=$remainder}
<td> </td>
{/section}
</tr>
</table>
NumCols is the number of columns you want, in the example is “6″, then when the column to be transformed into 7 new row. Hopefully this is useful for you. Happy coding.