Open vandenoever opened 4 years ago
The keywords and
and or
are also not allowed in brackets. This makes an expression link this not possible: {% if (a and b) or (c and d) %}
.
Now that the function containing
has become stricter and will not work on undefined variables, This old expression:
{% if a is containing("a") or b is containing("b") %}
needs a check on the existence of a
and b
:
{% if a and a is containing("a") or b and b is containing("b") %}
but since or
has a higher precedence in Tera this expression needs parentheses.
Ah I didn't think of that when I changed the parentheses handling :/ I'm waiting for pest v3 to rewrite the grammar though since it will have quite a few changes apparently.
Bumping, it would be wonderful if and
/ or
were allowed in parentheses to allow explicit / custom precedence.
The keywords
and
andor
are also not allowed in brackets.
{% if (a > b) and (a > c) %}
{{ "a is highest!" }}
{% endif %}
in
operator (https://tera.netlify.app/docs/#in-checking)
{% if (person in groupA) and (person in groupB) %}
{{ person ~ " is in both the groups." }}
{% endif %}
Sometimes parentheses may not be required due to operator associativity and precedence but in general, expressions should be allowed to be grouped in parentheses as it increases the code readability and assures the intended operation flow irrespective of the operator associativity and precedence.
v2 will fix all the operator precedences/parentheses issues and will be the focus after the next release of Zola
(I just checked with the experimental parser I have and all the examples in this thread are parsed correctly)
Does it also handle these two:
{{ not (not a) }}
{{ not not a }}
Yes
Great! Looks like we got the parser we needed :) Nice work!
In Tera 0.11 an expression like this was possibe:
In Tera 1, this gives an error: