Question

My PHP code assigns an array to a Smarty variable that can be accessed in the following way:

{$foo.123.name}
{$foo.456.name}
...

The 123, 456, etc. indexes in the array are dynamically assigned (based on some logic that includes the database). Since they are dynamically assigned, I cannot just put 123, etc. in the template file. However, those numbers are in another Smarty variable, say:

{$bar.id}

How do I use this $bar.id in place of the 123, 456?

Was it helpful?

Solution

For Smarty3:

{$foo.{$bar.id}.name}

For Smarty2:

{assign var="bid" value=$bar.id}
{$foo.$bid.name}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top