Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

creating an array and append values to it in smarty template

Tags:

append

smarty

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?

like image 907
MJQ Avatar asked Sep 14 '25 05:09

MJQ


2 Answers

Use append. I'm not sure if this is also available in Smarty 2

{append var='sizearr' value='' index=0}

like image 60
sofl Avatar answered Sep 17 '25 18:09

sofl


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]}
like image 20
acme Avatar answered Sep 17 '25 20:09

acme