[Django]-How can I use a Django template tag for greater than on a forloop.counter?

2👍

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

EDIT: Django now includes the smart if tag, so if you’re on the latest version then you won’t need that snippet.

5👍

If you only need greater-than, you can use the following easy snippet (put it into app/templatetags/greaterthan.py):

from django import template
register = template.Library()

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

And in a template:

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

Leave a comment