I'm trying to send an associative array into a Twig template I am including:
{% include 'my-template.twig' with {
items: [
[
'property' => 'value',
'other' => 'value'
],
[
'property' => 'value',
'other' => 'value'
]
]
} %}
I get this error:
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 ",")
It would seem it doesn't like =>
. Is it my syntax? Is there a way to accomplish this?
change associative array start and end []
to {}
and keys =>
to :
[
{
'property':'value',
'other':'value'
},
{
'property':'value',
'other':'value'
}
]
http://twig.sensiolabs.org/doc/templates.html#literals
{% include 'my-template.twig' with {
items: {
{
'property': 'value',
'other': 'value'
},
{
'property': 'value',
'other': 'value'
}
}
} %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With