views:

7654

answers:

4
Array $imagelist:

Array ( 
    [additional] => Array ( 
     [count] => 2 
     [image] => Array ( 
      [nokia_e61_1.jpg] => Array ( 
       [name_body] => nokia_e61_1 
       [name_ext] => jpg 
      ) 
      [nokia_e61_2.jpg] => Array ( 
       [name_body] => nokia_e61_2 
       [name_ext] => jpg 
      ) 
      [nokia_e61_3.jpg] => Array ( 
       [name_body] => nokia_e61_3 
       [name_ext] => jpg 
      ) 
      [nokia_e61_4.jpg] => Array ( 
       [name_body] => nokia_e61_4 
       [name_ext] => jpg 
      ) 
     ) 
    ) 
    [main] => nokia_e61 
)

The value nokia_e61_1.jpg is kept in {$getvars.imagename}.

I wrote {$imagelist.additional.image.`$getvars.imagename`.name_body} but it doesn't work.

Please help.

+2  A: 

see if {$imagelist.additional.image[$getvars.imagename].name_body} works

NoWhereMan
no, it doesn`t works :(
looks like it does to me, I've just tried with $a[$b.c].d and it worked
NoWhereMan
+1  A: 
{php}echo $imagelist['additional']['image'][$getvars['imagename']]['name_body'];{/php}
strager
+1  A: 

Restructure the array, the keys for the inner 'images' offset are redundant anyway:

        $imagelist = array('additional' => array('count' => 2,
                                                 'image' => array(
                                                                array('name_body' => 'nokia_e61_1',
                                                                      'name_ext'  => 'jpg'),
                                                                array('name_body' => 'nokia_e61_2',
                                                                      'name_ext'  => 'jpg'),
                                                                array('name_body' => 'nokia_e61_3',
                                                                      'name_ext'  => 'jpg'),
                                                                array('name_body' => 'nokia_e61_4',
                                                                      'name_ext'  => 'jpg')
                                                                 )
                                                ),
                           'main' => 'nokia_e61'
                         );

Gives you numerically indexed images:

array(2) {
  ["additional"]=>
  array(2) {
["count"]=>
int(2)
["image"]=>
array(4) {
  [0]=>
  array(2) {
    ["name_body"]=>
    string(11) "nokia_e61_1"
    ["name_ext"]=>
    string(3) "jpg"
  }
  [1]=>
  array(2) {
    ["name_body"]=>
    string(11) "nokia_e61_2"
    ["name_ext"]=>
    string(3) "jpg"
  }
  [2]=>
  array(2) {
    ["name_body"]=>
    string(11) "nokia_e61_3"
    ["name_ext"]=>
    string(3) "jpg"
  }
  [3]=>
  array(2) {
    ["name_body"]=>
    string(11) "nokia_e61_4"
    ["name_ext"]=>
    string(3) "jpg"
  }
}

} ["main"]=> string(9) "nokia_e61" }

//and then the smarty bit
{$imagelist.additional.image[0].name_body}
{$imagelist.additional.image[1].name_body}
{$imagelist.additional.image[2].name_body}
{$imagelist.additional.image[3].name_body}
karim79
+2  A: 

I don't like smarty for this, nevertheless I use it. Here's extract form documentation

{$foo.$bar}   <-- display variable key value of an array, similar to PHP $foo[$bar]

To be able to do it, you have to

{assign var='key' value=$getvars.imagename}
{$imagelist.additional.image.$key.name_body}

Hope it helps

michal kralik