I'd like to get the value of an element by key within an if statement.
Example:
works:
{{ example[5] }}
doesn't work:
{% if example2 is example[5] %} something ... {% endif %}
Exception thrown:
Unexpected token "punctuation" of value "[" ("end of statement block" expected)
Thank you very much
Kind regards
Instead of
{% if example2 is example[5] %} something ... {% endif %}
try changing 'is' to '=='
{% if example2 == example[5] %} something ... {% endif %}
Maybe you should use the attribute
function to get the object or array value. This link may help you
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