dynamic array key in smarty

php, smarty, smarty3

Solution

You can use variable for indexes, but you cannot build string the way you tried. Try to build a custom variable before:

{$myIndex = "param_{$k.id}_{$p.num}"}
{if $smarty.get.$myIndex eq $key}
    ...

This should work.

Problem

I just want to know how to access an array in SMARTY that have generated index via smarty. I want to access it later. Got something like this: ``` {if $smarty.get.{param_{$k.id}_{$p.num}} eq $key} ``` and I like to access `$smarty.get.(dynamic generated index)` Tried a couple variations, but didn't have any luck.

Original source