I have the following loop in my jinja2 template
{% for item in list if item.author == 'bob' %}
I am trying to get the first 5 items who have bob as an author.
I tried doing
{% for item in list if item.author == 'bob' and loop.index <= 5 %}
but it returned an undefined error.
How to make it work?
EDIT:
you can simply nest the expressions?, i.e.
{% for item in list if item.author == 'bob' %}
{% if loop.index <= 5 %}
do something
{% endif %}
{% endfor %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With