From the course: Flask Essential Training

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Template inheritance

Template inheritance

- [Instructor] First up control structures. These are just like the control structures you use in Python. You can use them to add logic to your templates. Let's start with loops. Continuing from our previous example, let's say you have a list of items you want to display and here's how you would look through them. I added a list of items. I will pass this piece of data to my template. In index.html, I'm opening a UL tag inside it, I will add a for loop. Next, a LI tech add in an item using Jinja template. Add in the for loop with an endfor keyword. This will create a list item for each element in the items list. Next conditionals, they let you run different code based on certain conditions. For example, if you want to display a special message for admin users, you will enclose that conditional in curly braces and percent signs, and you will add that block with an and if statement. So this checks if the user is an admin and displays an appropriate message for the admin. Filters are a…

Contents