How to keep track of iterations through a for loop in my template?

2007-10-01 Thread Greg

Hello,
I have a table in my template that will contain an x number of rows
depanding on what I get back from the view.  I want my table row
background color to rotate between red and white.  As of now, I don't
know how to keep track of each iteration through my for loop to set
the appropriate bgcolor.

Any suggestions?

Thanks


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



Re: How to keep track of iterations through a for loop in my template?

2007-10-01 Thread Malcolm Tredinnick

On Mon, 2007-10-01 at 14:59 -0700, Greg wrote:
> Hello,
> I have a table in my template that will contain an x number of rows
> depanding on what I get back from the view.  I want my table row
> background color to rotate between red and white.  As of now, I don't
> know how to keep track of each iteration through my for loop to set
> the appropriate bgcolor.
> 
> Any suggestions?

This is documented in the documentation for the "for" tag (which is what
I presume you are using to iterate over the table rows). Have a look at
the forloop.counter and forloop.counter0 variables you have access to in
the template (see [1]).

However, for this type of use-case, the cycle tag ([2]) is probably more
what you need.

[1] http://www.djangoproject.com/documentation/templates/#for
[2] http://www.djangoproject.com/documentation/templates/#cycle

Regards,
Malcolm



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



Re: How to keep track of iterations through a for loop in my template?

2007-10-01 Thread jake elliott

hi greg

Greg wrote:
> Hello,
> I have a table in my template that will contain an x number of rows
> depanding on what I get back from the view.  I want my table row
> background color to rotate between red and white.  As of now, I don't
> know how to keep track of each iteration through my for loop to set
> the appropriate bgcolor.
> 
> Any suggestions?

i think you want {% cycle %}:

http://www.djangoproject.com/documentation/templates/#cycle

best,
jake

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



Re: How to keep track of iterations through a for loop in my template?

2007-10-01 Thread George Vilches

Greg wrote:
> Hello,
> I have a table in my template that will contain an x number of rows
> depanding on what I get back from the view.  I want my table row
> background color to rotate between red and white.  As of now, I don't
> know how to keep track of each iteration through my for loop to set
> the appropriate bgcolor.

You're thinking too hard about the problem. :)

http://www.djangoproject.com/documentation/templates/

Search for the word "cycle":

{% for o in some_list %}
 
 ...
 
{% endfor %}


Good luck!
gav

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



Re: How to keep track of iterations through a for loop in my template?

2007-10-02 Thread Henning Hraban Ramm

Am 2007-10-01 um 23:59 schrieb Greg:

> I have a table in my template that will contain an x number of rows
> depanding on what I get back from the view.  I want my table row
> background color to rotate between red and white.  As of now, I don't
> know how to keep track of each iteration through my for loop to set
> the appropriate bgcolor.

Another solution is changing the CSS class of the rows afterwards  
with a bit of JavaScript (I love jQuery for such).
It's a bit dirty, but I often need it if I dynamically change my  
forms/tables with JS anyway.

Greetlings from Lake Constance!
Hraban
---
http://www.fiee.net
https://www.cacert.org (I'm an assurer)



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