if
If is the conditional block — its contents are rendered only if the condition is true.
{% if editmode or previewmode %}
Visible for logged in users
{% else %}
Visible for everyone else
{% endif %}
There are
{% if count < 5 %}less than{% elsif count > 5 %}more than{% else %}exactly{% endif %}
5 items.
Some examples on how to work with different kind of conditions:
{% if element.email != '' %}
{{ element.email }}
{% endif %}
{% if element.name == 'peter' and element.name != 'John' %}
Hello you, Non-John Peter!
{% endif %}
{% if articles.size < 1 %}
No articles to display
{% endif %}
// Check if array contains desired value, e.g. ['foo', 'bar']
{% if array contains 'foo' %}
There is a 50/50 chance that this array also contains "bar" :)
{% endif %}
// Check if string contains desired value, e.g 'hello world'
{% if some_string contains 'hello' %}
String contains "hello"
{% endif %}