On Tue, 2009-03-17 at 16:03 -0500, Jay Deiman wrote:
[..].
> Template code:
> ======================
> 
> Output "eggs": {{ foo.{{ spam }} }}
> 
> ======================
> 
> Is there any way at all to do something like that?

Write a custom filter that takes "spam" as an argument and does the
lookup for you.

[...]
> In the template, while looping through "list1", I want to be able to 
> directly access by index the corresponding value in "list2".  I know the 
> following doesn't work, but again, it seems like there should be a way 
> to do this.  Note that this is a greatly simplified version of what I'm 
> actually trying to accomplish!!

The general plan is to either (a) write a custom template filter to do
this (similar to the last case and use forloop.counter as the argument)
or (b) stop trying to programming in templates and do programming in
your views instead. Arrange the datastructures that are passed to the
templates so that you can retrieve all the data value in a single loop.
Zip the lists together, or write a function that returns the
corresponding elements via an iterator and loop over that.

Django doesn't provide indirect variable references out of the box
intentionally.

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 [email protected]
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