Create an array in smarty template?
This does not answer my question. I have a list that I am retrieving from the database using a PHP
class and in the template, I have a foreach loop.
What I want to do is create a list from the data retrieved from the database. This what I have.
{assign list=[]}
{foreach from=$prescriptions item=prescription}
{$list[]=$prescription->drug}
{$prescription->drug|escape:'html'}
{/foreach}
{$list|print_r}<--- Really not needed as the above prints to the screen.
What's happening is the data is not being appended to the list. It is overwriting the last entry with each pass of the loop.
What I want is the list to be a string drug1,drug2,drug3,drug(n).
Now I get an error message.
/templates/prescription/general_list.html line 150]: syntax error: unrecognized tag: $list[]=$prescription->drug
Can't seem to find the right syntax for adding values to the array.