I want to create an array in smarty and do an append functionality in it! Like if I declare a variable in smarty template like {assign var=sizearr value=''} and then i want to append values to this in a loop, and i can access values like {sizearr.0}, how can i do that?
4 Answers
Use append. I'm not sure if this is also available in Smarty 2
{append var='sizearr' value='' index=0}
Comments
You can use this too:
{$sizearr[] = "Size value"}
Comments
You can simply use the smarty built-in function append :
Now lets take this example:
{assign var="ages" value=[] }
{for $i=1 to 3}
{append var="ages" value=$i }
{/for}
In the above example we didn't specify index parameter in the append function, so the value will be appended at the end of the ages array.
Hope this is helpful for everyone.