On Feb 17, 9:48 pm, "oggie rob" <[EMAIL PROTECTED]> wrote:
> > I find it useful to have the {% for %} tag syntax extended so that one can
> > write:
> > {% for a,b in L %} meaning the obvious thing
>
> You can do this. a,b return type is implicitly (a,b) in Python. In
> other words:
> {% for x in L %}
> {{ x.0 }}
> {{ x.1 }}
> {% endfor %}
You can do this of course but it does not help to make sense of the
template. E.g.
{% for key,value in L %}
{{ key }}->{{ value }}
{% endfor %}
looks neater than
{% for key_value in L %}
{{ key_value.0 }}->{{ key_value.1 }}
{% endfor %}
[...]
> This is starting to look like more logic in the template than you
> would normally use. I think the idea of the {% for %} tag has been
> (and should be) to be able to easily cycle through collections of data
> you've already set up. Most of the time you don't have to manipulate
> them in any way other than how you've collected the data in the first
> place. If you *DO* need to manipulate them, you should use views, not
> templates.
Following this argument there is no need for {% for ... in L reversed
%} as L can be reversed in the view :)
Here is an example:
IMHO which way round a table is displayed shouldn't really be the
concern of the view but rather of the template. Due to the nature of
HTML (where a table essentially is a list of rows) the current form of
{% for ... %} forces this *layout* decision to take place in the view
unless one writes a custom tag.
Of course this is a more general problem that my suggestion does not
solve completely but it has helped me in some cases to move layout
decisions from views to templates.
--
Arnaud
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To post to this group, send email to django-developers@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-developers?hl=en
-~----------~----~----~----~------~----~------~--~---