even and odd numbers within a template

299 views
Skip to first unread message

Juan Hernandez

unread,
Nov 24, 2009, 8:39:07 AM11/24/09
to Django users
Hey there people...

I've been coloring html tables using javascript for a while and now, we need to color our tables just with html. The CSS has been made to use one color for even rows and another one for odds. How can I know if a current template loop is odd or even? I've been trying many different things and none of them work

Thanx
jhv

Colin Copeland

unread,
Nov 24, 2009, 8:46:42 AM11/24/09
to django...@googlegroups.com
Juan,

The "cycle" template tag may help you here:

http://docs.djangoproject.com/en/dev/ref/templates/builtins/#cycle

colin
> --
>
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to django-users...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

--
Colin Copeland
Caktus Consulting Group, LLC
P.O. Box 1454
Carrboro, NC 27510
(919) 951-0052
http://www.caktusgroup.com

Kevin Renskers

unread,
Nov 24, 2009, 8:48:42 AM11/24/09
to Django users
{% for o in some_list %}
<tr class="{% cycle 'row1' 'row2' %}">
...
</tr>
{% endfor %}
Reply all
Reply to author
Forward
0 new messages