creating an array and append values to it in smarty template
13,177
Solution 1
Use append. I'm not sure if this is also available in Smarty 2
{append var='sizearr' value='' index=0}
Solution 2
In smarty3 yould also use a more php-like approach:
{$sizearr[] = 'your value'}
and either loop through the array like
{foreach $sizearr as $value}
{$value@key}: {$value}
{/foreach}
or just hit a specific index:
{$sizearr[2]}
Solution 3
You can use this too:
{$sizearr[] = "Size value"}
Here you can see the full doc (Section Appending an array)
Author by
MJQ
Updated on June 05, 2022Comments
-
MJQ almost 2 years
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?