Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个关联数组分配给 Smarty 变量,如下所示:
$foo = array('my[content][hello]' => 'hello', 'my[content][goodbye]' => 'goodbye', ...
在模板文件中,如何访问hello?这失败了:
hello
{$foo.my[content][hello]}
我猜这是失败的,因为括号意味着我正在尝试访问数组的一部分。在这种情况下,我不是。括号只是变量名的一部分。想法?
尝试
{$foo.{'my[content][hello]'}}
或者
{$foo['my[content][hello]']}
或(如果所有其他方法都失败了[意味着您仍在 Smarty2 上]):
{assign var=key value='my[content][hello]'} {$foo.$key}