Besides mathematical, comparison, and logical operators, it is also possible to use a series of additional operators that do not fit into the traditional categories but are widely used to complement the code. Other supported operators: |: Applies a filter to a variable. Example of use:
{{ 'apple'|upper }}
{# Returns 'APPLE' #}
~: Concatenates two values, usually strings. Example of use:
{{ 'Hello, ' ~ 'World!' }}
{# Returns 'Hello, World!' #}
.: Accesses a property or method of an object, or an element of an array. Example of use:
{{ order.number }}
{# Accesses the 'number' property of the 'order' object #}
[]: Accesses a specific element in a sequence (array). Example of use:
{{ fruits[0] }}
{# Accesses the first element of the 'fruits' array #}
?:: Ternary operator. Returns the value on the left if it is defined and not null; otherwise, returns the value on the right. Example of use:
{{ first_name ?: 'Guest' }}
{# Returns 'Guest' if 'first_name' is not defined or is null #}
??: Checks if a value is defined and not null; otherwise, returns a default value. Example of use:
{{ order.total_price ?? 'Value not defined' }}
{# Returns 'Value not defined' if 'order.total_price' is not defined or is null #}