in in particular.
Basics
Notation
Operators are used directly within an expression. They can occur in an output as well as in a variable assignment or a condition. To output the result of an expression directly in the template, the output notation is used:Operators in outputs and conditions
Operators are particularly often used in these situations:- when accessing values in maps or lists
- in calculations
- in comparisons in
ifconditions - when linking multiple conditions
- when checking whether a value is contained in a list or map
. and [] for access, mathematical operators, comparison operators, logical operators, and in.
Order and parentheses
As soon as multiple operators are combined in an expression, parentheses should be used to make the desired order unambiguous. This not only increases readability but also prevents misunderstandings in more complex conditions. Example:{{= ($myPrice > 0 and $stock > 0) or $myIsBackorderAllowed }}
Recommendation:
- Simple expressions can be written directly.
- For mixed comparisons and logical connections, parentheses should be used.
- Especially with
and,or, andnot, a clear structure is important.
List of operators
Dot operator .
The dot operator is used to access an attribute of a map. The existing operators page describes the dot operator as standard access to attributes of an object and also shows that it does not work with list indices.
Usage exampleTypical examples are accessing product data, customer data, or other structured values. Notation
Index operator []
The index operator is used to access values in lists or maps. With maps, the key is specified in square brackets. With lists, the numeric index is used. According to the existing documentation, a variable can also be used in the index operator.
Usage exampleUseful for dynamic keys or for accessing a specific list element. Notation
0.
Addition operator +
The operator + is used to add numeric values. The current functions page additionally documents that + can also be used to concatenate strings as well as merge lists. This contradicts the older operators page; this draft therefore follows the newer functions page.
Usage exampleCan be used for calculations, but also for composing texts or merging lists. Notation
str().
Subtraction operator -
The operator - subtracts one value from another. The operators page documents - as one of the basic mathematical operators.
Usage exampleUseful for price differences, discounts, or remaining quantities. Notation
Multiplication operator *
The operator * multiplies two numeric values. It is part of the mathematical operators documented on the operators page.
Usage exampleTypical for quantity and price calculations. Notation
Division operator /
The operator / divides one numeric value by another numeric value. This operator is also documented in the existing math overview.
Usage exampleHelpful for averages, ratios, or conversions. Notation
For divisions, you should ensure that the divisor is not
0.
Modulo operator %
The modulo operator % returns the remainder of a division. The operators page expressly names % as the modulo operator.
Usage exampleUseful for checking even and odd values or implementing grid logic in lists. Notation
Equality operator ==
The operator == checks whether two values are equal. According to the existing reference, comparison operators always return a boolean value, i.e., true or false.
Usage exampleCan be used for status checks, country checks, or template logic. Notation
Inequality operator !=
The operator != checks whether two values are unequal. It also belongs to the comparison operators documented on the operators page.
Usage exampleUseful when a value explicitly must not correspond to a certain state. Notation
Less than <
The operator < checks whether the left value is less than the right value. According to the current operators page, comparison operators are intended for such value comparisons.
Example – check price limit
Greater than >
The operator > checks whether the left value is greater than the right value.
Example – check minimum order value
Less than or equal <=
The operator <= checks whether a value is less than or equal to another value.
Example – check stock
Greater than or equal >=
The operator >= checks whether a value is greater than or equal to another value.
Example – check minimum age or threshold
Logical and
The operator and links two conditions. The result is only true if both conditions are met. Exactly this behavior is described with examples on the operators page.
Usage exampleUseful when multiple prerequisites must be met at the same time. Notation
Logical or
The operator or links two conditions. The result is true if at least one of the conditions is met. According to the existing reference, or belongs to the logical operators.
Usage exampleSuitable for alternative approvals or special cases. Notation
Logical not
The operator not reverses the truth value of an expression. not is also part of the logical operators documented on the operators page.
Usage exampleHelpful when checking that a condition is not met. Notation
Containment operator in
The operator in checks whether the left value is contained in the right object. The existing operators page expressly documents in as a containment operator and shows 1 in [1, 2, 3] as an example.
Usage exampleUseful for country lists, allowed values, color selections, or whitelists. Notation
