Conditionals

Explains how to create conditions in templates.

if, elif, and else tags

These tags are used to evaluate a variable. If that variable is “true,” the contents of the block will be displayed.

Syntax

Below is the syntax of these tags:

{% if condition %}
    ....
{% elif condition %}
    ....
{% else %}
    ....
{% endif %}

NOTE: It is required to always use an end tag {% endif %} at the end of the if block.

Example

We will use the example from the previous lesson, but this time we will only display a list of the TV shows that have a rating o 8.5.

Get hands-on with 1400+ tech skills courses.