Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Can we get an {% empty %} tag? #77

priestc opened this Issue · 3 comments

3 participants


Django has this really cool tag called {% empty %}, which lets you do this:

{% for item in list %}
    <tr><td>{{ item }}</td></tr>
{% empty %}
    <tr><td>Nothing to show!</td></tr>
{% endfor %}

which is short for

{% if list %}
    {% for item in list %}
        <tr><td>{{ item }}</td?</tr>
    {% endfor %}
{% else %}
    <tr><td>Nothing to show!</td></tr>
{% endif %}

Since switching to jinja, I have really missed this tag :(


That already exists. Use {% else %} on a for loop. Unfortunately we had else before Django created empty and renaming it now to match Django semantics is kinda weird.


oh, i see. Maybe put a note of that in the "Switching from other Template Engines" under then django section?

@njl njl referenced this issue from a commit
@njl njl Fix #77 by adding note to switching document
Explaining that {% empty %} in Django loops is {% else %} in Jinja2.
@njl njl referenced this issue from a commit in njl/jinja2
@njl njl Fixes issue #77 by adding explanation to docs
Points out that the Django empty is replaced by the
Flask else.

I don't see this in the switching documentation. It is mentioned in the control structures:for documentation but it would be helpful to have it in the switching doc...

@mitsuhiko mitsuhiko closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.