Вопрос

I have an associative array assigned to a Smarty variable, something like this:

$foo = array('my[content][hello]' => 'hello', 'my[content][goodbye]' => 'goodbye', ...

In the template file, how do I access hello? This fails:

{$foo.my[content][hello]}

My guess it that is fails because the brackets means I'm trying to access parts of an array. In this case, I'm not. The brackets are just part of the variable name. Thoughts?

Это было полезно?

Решение

try

{$foo.{'my[content][hello]'}}

or

{$foo['my[content][hello]']}

or (if all else fails [meaning you're still on Smarty2]):

{assign var=key value='my[content][hello]'}
{$foo.$key}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top