How can I use a Django template tag for more than forloop.counter?

I need the effect of the "ifgt" template tag on the django template page:

{%ifgt forloop.counter 10%}<!---special greater than 10 code--!>{%endif%}
+3
source share
2 answers

This Django snippet will give you a smart if tag that you can use with operators such as: http://www.djangosnippets.org/snippets/1350/

EDIT: Django now includes a smart if tag, so if you are using the latest version, you will not need this snippet.

+2
source

If you only need more than that, you can use the following simple snippet (put it in the /templatetags/morethan.py application):

from django import template
register = template.Library()

@register.filter
def gt(a, b):
    return a > b

And in the template:

{% load greterthan %}
{% if forloop.counter|gt:10 %}...{% endif %}
+4
source

Source: https://habr.com/ru/post/1712877/


All Articles