Re: Optional else block in for

2008-03-31 Thread Evert Rol

Perhaps this is useful: http://www.djangosnippets.org/snippets/546/

It even has a ticket: http://code.djangoproject.com/ticket/6398  with,  
of course, ensuing discussion.


>
> I was looking at jinja[1] and there was one feature which I really
> liked
> "for loops have an optional else block executed if there was no
> iteration."
>
> Right now most of my for loops are like,
>
> {% if comments %}
>
> {% for comment in comments %}
> {{comment}}
> {% endfor %}
>
> {% else %}
> There are no comments.
> {% endif %}
>
> It would be much `cooler` to write
>
> {% for comment in comments %}
> {{comment}}
> {% else %}
> There are no comments.
> {% endfor %}
>
> Of course this is not a huge improvement, but I need to do this so
> many times, might be this is a common use case. :)
> >


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Optional else block in for

2008-03-31 Thread shabda

I was looking at jinja[1] and there was one feature which I really
liked
"for loops have an optional else block executed if there was no
iteration."

Right now most of my for loops are like,

{% if comments %}

{% for comment in comments %}
{{comment}}
{% endfor %}

{% else %}
There are no comments.
{% endif %}

It would be much `cooler` to write

{% for comment in comments %}
{{comment}}
{% else %}
There are no comments.
{% endfor %}

Of course this is not a huge improvement, but I need to do this so
many times, might be this is a common use case. :)
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---