Mic*_*nch 5 php associative-array include twig
我正在尝试将关联数组发送到我包含的Twig模板中:
{% include 'my-template.twig' with {
items: [
[
'property' => 'value',
'other' => 'value'
],
[
'property' => 'value',
'other' => 'value'
]
]
} %}
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
PHP Fatal error: Uncaught exception 'Twig_Error_Syntax' with message 'An array element must be followed by a comma. Unexpected token "operator" of value "=" ("punctuation" expected with value ",")
它似乎不喜欢=>.这是我的语法吗?有没有办法实现这个目标?
改变关联数组的开始和结束[],以{}及密钥=>对:
[
{
'property':'value',
'other':'value'
},
{
'property':'value',
'other':'value'
}
]
Run Code Online (Sandbox Code Playgroud)
http://twig.sensiolabs.org/doc/templates.html#literals