Sparsh Gupta
Sparsh Gupta

Reputation: 2233

Smarty assign value to an array variable index

I am using SMARTY and I need to create an array and assign value to a particular index of it.

Something like:

{foreach from=$a key='i' item='b'}
//Some calculations here giving me a VALUE
ARRAY[$i] = $VALUE;
{/foreach}

Now the problem is when I am using standard Smarty Assign syntax

{assign var='array.$i' value=$VALUE}
{assign var='array[$i]' value=$VALUE}
{assign var=$array.$i value=$VALUE}
{assign var='$array[$i]' value=$VALUE}

its not working. I need to use this array later in the code and hence need it in an array format only

Upvotes: 5

Views: 16557

Answers (1)

onteria_
onteria_

Reputation: 70587

Have you tried the assign shorthand instead?

{$array.$i = $VALUE}

Upvotes: 15

Related Questions