October 2018
Intermediate to advanced
332 pages
8h 9m
English
Using if statements in Jinja is similar to using them in Python. Anything that returns, or is, a Boolean determines the flow of the code, as shown in the following code:
{%if user.is_logged_in() %}
<a href='/logout'>Logout</a>
{% else %}
<a href='/login'>Login</a>
{% endif %}
Filters can also be used in if statements, as follows:
{% if comments | length > 0 %}
There are {{ comments | length }} comments
{% else %}
There are no comments
{% endif %}