Hey i want to reverse the output of the following. Can you help me?
{% set page 7 %}
{% for i in range(1,6) %}
{% set back_link = page - i %}
{{back_link}}
{% endfor %}
Output: 6 5 4 3 2
Wanted: 2 3 4 5 6
You can reverse a list in Jinja2 using the reverse
filter
{% for x in mylist|reverse %}
{{x}}
{% endfor %}
This is compatible with range
so you could use:
{% for i in range(1, 10)|reverse %}
{{i}}
{% 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