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
Assigning values to an element in an array is similar to assigning values to scalar variables. Simply reference an individual element of an array using the array name and the index inside parentheses, then use the assignment operator (=) followed by a value.
Variables in Smarty can be either displayed directly or used as arguments for functions, attributes and modifiers, inside conditional expressions, etc. To print a variable, simply enclose it in the delimiters so that it is the only thing contained between them. Example 4.1. Example variables.
Have you tried the assign shorthand instead?
{$array.$i = $VALUE}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With