The for ... empty pattern in templates is common and useful:
<https://docs.djangoproject.com/en/dev/ref/templates/builtins/#for-empty>
But this is another common pattern:
{% if my_bonnet.bees %}
<ul>
{% for bee in my_bonnet.bees %}
<li>{{ bee }}
...
In other words, we have to check first for items in the iterable before
creating a <ul> or whatever other furniture to put them in.
The problem here is that my_bonnet.bees gets asked for twice, and it could be
my.bonnet(), some very expensive function.
One solution is to put everything inside:
{% with my_bonnet.bees as bees %}
but now:
* we've used up a precious level of indentation
* we've introduced a new variable in the templates to worry about
* it just feels a bit fussy
Is this enough of an issue to make it worthwhile implementing some other
approach in the template system?
Daniele
--
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-developers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.