<p>The <strong>for</strong> tag has an <strong>else</strong> clause by which you can render a replacement block if no iteration took place because the sequence was empty.</p>

<pre><code>&lt;ul&gt;
    {% for user in users %}
        &lt;li&gt;{{ user.username|e }}&lt;/li&gt;
    {% else %}
        &lt;li&gt;&lt;em&gt;no user found&lt;/em&gt;&lt;/li&gt;
    {% endfor %}
&lt;/ul&gt;
</code></pre>

<p>reference: <a href="http://twig.sensiolabs.org/doc/tags/for.html#the-else-clause">http://twig.sensiolabs.org/doc/tags/for.html#the-else-clause</a></p>

CC BY-SA 3.0
2014-07-12T01:54:29.060Z
I thought I had, I think my internet connection glitched when I did. Thanks for letting me know!
cballenar
CC BY-SA 3.0
2014-07-12T01:55:00.717Z
Oh, wait... No. I can do it in 14 hours :P
cballenar
CC BY-SA 3.0
2014-07-10T16:10:27.550Z
2014-07-12T01:16:06.630Z
2014-07-12T01:16:06.630Z
cballenar
<p>I thought this would be very easy but I'm having a hard time figuring it out.</p>

<p>How do you output a warning/message if there are no entries to loop through?</p>

<pre><code>{% set entries = craft.entries.section('news').limit(5).find() %}

{% if entries|length %}
    {% for entry in entries %}
      {# Do Loop #}
    {% endfor %}
{% else %}
    &lt;p&gt;No entries found.&lt;/p&gt;
{% endif %}
</code></pre>

<p>Or am I just sleepy and approaching this all wrong?</p>

<entries><templating><forloop>
How do you return a message if no entries are found?
# How do you return a message if no entries are found?

(Asked by: username_0 on 2014-07-10)

I thought this would be very easy but I'm having a hard time figuring it out.
How do you output a warning/message if there are no entries to loop through?
{% set entries = craft.entries.section('news').limit(5).find() %}

{% if entries|length %}
    {% for entry in entries %}
      {# Do Loop #}
    {% endfor %}
{% else %}
    No entries found.
{% endif %}

Or am I just sleepy and approaching this all wrong?

**Tags:** entries, templating, forloop


---

## 1 answers

### Answer by username_0 on 2014-07-10. Score: 13 | Accepted answer

The for tag has an else clause by which you can render a replacement block if no iteration took place because the sequence was empty.

    {% for user in users %}
        {{ user.username|e }}
    {% else %}
        no user found
    {% endfor %}


reference: http://twig.sensiolabs.org/doc/tags/for.html#the-else-clause

> **Comments:**
> **username_0**: I thought I had, I think my internet connection glitched when I did. Thanks for letting me know!  
> **username_0**: Oh, wait... No. I can do it in 14 hours :P  

---

