Smarty:如何引用关联数组索引

2022-08-31 00:39:03
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 
) 

该值保存在 中。nokia_e61_1.jpg{$getvars.imagename}

我写了,但它不起作用。{$imagelist.additional.image.`$getvars.imagename`.name_body}

请帮忙。


答案 1

看看是否有效{$imagelist.additional.image[$getvars.imagename].name_body}


答案 2

我不喜欢聪明,但我使用它。这是摘录表单文档

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

为了能够做到这一点,你必须

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

希望它有帮助