Reputation:
I've a problem with Smarty 3 foreach loop and gettext translations. In my controller i intercept the variables from a MySQL database and then i create an array:
CONTROLLER:
array_categories[] = array(
'name_cat_it' => $name_cat_it,
'name_cat_en' => $name_cat_en,
);
$smarty->assign('array_cat', $array_categories);
TEMPLATE:
{foreach name=categorie key=key item=value from=$array_cat}
{$value.name_cat_it}
{/foreach}
Till now everything is ok, but i would like to do something like this:
{foreach name=categorie key=key item=value from=$array_cat}
{$value.name_cat_{$lang}}
{/foreach}
$lang can be 'it' o 'en'. Is this possible inside a foreach loop? Outside the loop i have no problem doing this for the meta title or the meta description.
Thanks a lot!
M
Upvotes: 1
Views: 453
Reputation: 3245
Yes, you can use a temporal variable to compose the name:
{$name_lang='name_cat_'|cat:$lang}
{foreach name=categorie key=key item=value from=$array_cat}
{$value.$name_lang}
{/foreach}
Upvotes: 1