0

I have problem with displaying my array in smarty. It looks like this. Declaration of array:

index.php:

$rewrites = array(
'en' => array(
'homepage' => 'homepage'
),

'de' => array(
'homepage' => 'zuhause'
),
);

$smarty->assign('rewrites', $rewrites);

And in template file:

{$rewrites|@print_r}
{$rewrites[de][homepage]}

First line prints whole array like it is, so array is assigned. But second line shows nothing, why? How to do it properly? If I do it like this {$rewrites.de.homepage} it works but I really need to declare my array value like this {$rewrites[de][homepage]} because 'de' comes from other variable, that define current language. My target is {$rewrites[$lang][homepage]} for example.

b4rt3kk
  • 1,419
  • 3
  • 17
  • 26
  • http://stackoverflow.com/questions/648042/smarty-how-to-reference-to-the-associative-array-index – Mike B Jul 05 '13 at 09:14

3 Answers3

0

Use:

{$rewrites[$lang]['homepage']}

You can use also:

{$rewrites.{$lang}.homepage}
Plamen Nikolov
  • 2,643
  • 1
  • 13
  • 24
0

Simply try this:

{$rewrites.de.homepage}
Minesh
  • 2,284
  • 1
  • 14
  • 22
-1

you can do is as follows {$rewrites[$lang].homepage}

DevZer0
  • 13,433
  • 7
  • 27
  • 51