Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

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

Closed
priestc opened this Issue Dec 2, 2011 · 3 comments

Comments

Projects
None yet
3 participants

priestc commented Dec 2, 2011

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 :(

Owner

mitsuhiko commented Dec 3, 2011

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.

priestc commented Dec 3, 2011

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

njl added a commit to njl/jinja2 that referenced this issue Mar 13, 2012

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 added a commit that referenced this issue May 19, 2013

@mitsuhiko mitsuhiko closed this May 20, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment