Skip to main content
Version: 0.5

Operators

This page provides a reference for all the available operators that can be used when defining conditions in templates with the if and unless tags.

Equality and comparison operators

The following equality and comparison operators can be used:

OperatorDescription
==Equals
!=Not equals
>Greater than
>=Greater than or equals
<Less than
<=Greater than or equals

For example:

{% if my_var == 0 %}
Zero!
{% elsif my_var >= 1 %}
One or greater!
{% else %}
Other!
{% endif %}

Logical operators

The following logical operators can be used:

OperatorDescription
&&Logical AND
||Logical OR
! or notLogical negation

For example:

{% if my_var == 0 %}
Zero!
{% elsif my_var == 1 && other_var == "foobar" %}
One!
{% elsif !additional_var %}
Something else!
{% else %}
Other!
{% endif %}

Inclusion operator

The in operator is the inclusion operator that can be used in if or unless conditions. This operator allows to check for the presence of a substring in another string or for the presence of a value in an array or tuple.

For example:

{% if "Top 10" in blog.title %}
Top 10 blog article
{% endif %}

{% if "red" in colors %}
Red color available
{% endif %}