> This problem's kinda hard to explain, but I'll try my best. I've got a
> list variable : notes_list which looks like: {'note 1', 'note2' etc..}
> 
> I'm using this variable within a forloop and I want it to cycle based
> on the number of loop (notes_list.0 for the first loop, notes_list.1
> for the second time it loops).
> 
> I tried using the following code:
> 
> {{notes_list.forloop.counter0}}
> 
> but that didn't work. Any ideas on how to solve this problem?

If I understand what you're trying to do, you want to pair one 
list ("List A", which you're iterating over in your loop) with 
items in a 2nd list ("List B", your notes_list above) so you're 
trying something like


   view:

   render_to_response('foo.html', {
     'lista': lista,
     'listb': notes_list
     })


   template:

   {% for item in lista %}
    {{ item }}
    <p>{{ listb.forloop.counter0 }}</p> <!-- fail -->
   {% endfor %}


If this is the case, it sounds like you want to use the Python 
"zip()" call to pair up the items:

new view:

   render_to-response('foo.html', {
     'pairs': zip(lista, notes_list)
     })

0.96 and earlier version template:
   {% for pair in pairs %}
    {{ pair.0 }}
    <p>{{ pair.1 }}</p>
   {% endfor %}

development version template:
   {% for itema, itemb in pairs %}
     {{ itema }}
     <p>{{ itemb }}</p>
   {% endfor %}

Hope this helps,

-tim





--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to