Reputation: 1363
I have a flask project
in which I need to add each value of i
from a for-loop
into the div
tags class
.
Something like :
{% for i in range(5) %}
<div class="cls{{ i }}">
{% endfor %}
In each looping it should give
cls1,cls2,cls3 etc
Upvotes: 0
Views: 1295
Reputation: 2297
Jinja templating allows you to perform mathematic operations inside the {{}}
So for getting your class attributes as cls1
, cls2
, .. cls5
you could just do the following
{% for i in range(5) %}
<div class="cls{{ i+1 }}">
{% endfor %}
Which will render the following:
<div class="cls1">
<div class="cls2">
<div class="cls3">
<div class="cls4">
<div class="cls5">
Upvotes: 1