Control Flow

In this lesson, we will learn how to add control flow blocks in the Jinja templating language.

We'll cover the following

Introduction

Jinja also provides syntax to handle the control flow of the application inside its templates. Loops and conditions can be added to the templates using a pythonic syntax provided by Jinja.

Loops

The syntax of for loops in Jinja is very similar to pythonic syntax.

{% for elements in array %}
    ...
{% endfor %}

📌 Note: You must always end the for loop using {% endfor %}.

Consider the example of a dictionary we covered in the last lesson. If we want to traverse the whole dictionary we can do it as follows:

Get hands-on with 1200+ tech skills courses.