views:

1022

answers:

2

I want the effect of an "ifgt" template tag in a django template page:

{%ifgt forloop.counter 10%}<!---special greater than 10 code--!>{%endif%}
+1  A: 

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/

Eli Courtwright
Do you know if loading the "smart_if" template tags on a page will degrade the performance of normal "if" statements?
MikeN
I can't imagine that it would be worse enough to cause any kind of noticeable difference. I'd be incredibly shocked if there was so much as a 1 millisecond difference.
Eli Courtwright
+3  A: 

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 %}