It seem I have problem with a twig if statement.
{%if fields | length > 0 || trans_fields | length > 0 -%}
The error is:
Unexpected token "punctuation" of value "|" ("name" expected) in
I can't understand why this doesn't work, it's like if twig was lost with all the pipes.
I've tried this :
{% set count1 = fields | length %}
{% set count2 = trans_fields | length %}
{%if count1 > 0 || count2 > 0 -%}
but the if also fail.
Then tried this:
{% set count1 = fields | length > 0 %}
{% set count2 = trans_fields | length > 0 %}
{%if count1 || count2 -%}
And it still doesn't work, same error every time ...
So... that lead me to a really simple question: does Twig support multiple conditions IF ?
If I recall correctly Twig doesn't support
||
and&&
operators, but requiresor
andand
to be used respectively. I'd also use parentheses to denote the two statements more clearly although this isn't technically a requirement.Expressions
For more complex operations, it may be best to wrap individual expressions in parentheses to avoid confusion: