Friday, November 25, 2011

Re: iterating through lists in templates

On Fri, Nov 25, 2011 at 1:18 PM, marjenni <mark.jennings.email@gmail.com> wrote:
> Hi all,
>  Why does this not work?
>
>    {% for i in numberOfImages %}
>          <tr>
>         <td> {{ images.i}} </td>

It doesn't work because there is no variable interpolation inside a
template tag. That snippet asks for the attribute named 'i' on the
'images' variable.

As an earlier poster said, pass a list of images to output, and then
iterate through that list. If you need the ordinal of where you are in
the list, that is made available by the for tag:

https://docs.djangoproject.com/en/1.3/ref/templates/builtins/#for

Cheers

Tom

--
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 django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment