Ответ 1
Если я правильно помню, Twig не поддерживает операторы ||
и &&
, но требует использования or
и and
соответственно. Я также использовал бы круглые скобки для более четкого обозначения этих двух утверждений, хотя это технически не требуется.
{%if ( fields | length > 0 ) or ( trans_fields | length > 0 ) %}
Выражение
Expressions can be used in {% blocks %} and ${ expressions }.
Operator Description
== Does the left expression equal the right expression?
+ Convert both arguments into a number and add them.
- Convert both arguments into a number and substract them.
* Convert both arguments into a number and multiply them.
/ Convert both arguments into a number and divide them.
% Convert both arguments into a number and calculate the rest of the integer division.
~ Convert both arguments into a string and concatenate them.
or True if the left or the right expression is true.
and True if the left and the right expression is true.
not Negate the expression.
Для более сложных операций лучше всего заключить отдельные выражения в круглые скобки, чтобы избежать путаницы:
{% if (foo and bar) or (fizz and (foo + bar == 3)) %}