How can I autopopulate a table dynamically using PHP and Smarty?

I want to be able to create a table, setting a variable for the number of columns and using smarty have the table populated via an array.

Related tags: PHP

Credit: my own modified version of the solution found here

In the template file, use the following;

{if $data.sample_list}Sample table
{assign var="cols" value="5"}
{assign var="count" value="1"}
{section name=tr loop=$data.sample_list step=$cols}
{section name=td start=$ max=$cols loop=$$cols}
{if $count++ <= $data.sample_list_count}

Rating: 1

Propose a different solution...