views:

107

answers:

1

Hi, I am trying to access the contents of an array using forloop.counter0 in django templates but I can't get it working.

What I have is

{% for action in my_action_list %}
    {{another_list.forloop.counter0}}
{% endfor %}

Where my_action_list is a list and another_list is also a list. I have tried doing this manually e.g. {{another_list.0}} and this works and I have also tried {{forloop.counter0}} and this is printing out the correct index so not sure why its not working.

Any ideas?

+2  A: 

The templating engine is probably looking for a property called another_list.forloop, which of course doesn't exist.

If you want to loop through two lists simultaneously, the best solution may be to zip them in your view beforehand.

Ben James
+1: Do as much as possible in the view function. If the template gets complex, fix the view function.
S.Lott