Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 %}
    <p>No entries found.</p>
{% endif %}

Or am I just sleepy and approaching this all wrong?

share|improve this question
up vote 9 down vote accepted

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 %}
        <li>{{ user.username|e }}</li>
    {% else %}
        <li><em>no user found</em></li>
    {% endfor %}


share|improve this answer
why did you not check your answer as accepted if it solves your problem? – dralshehri Jul 12 '14 at 1:08
I thought I had, I think my internet connection glitched when I did. Thanks for letting me know! – cballenar Jul 12 '14 at 1:54
Oh, wait... No. I can do it in 14 hours :P – cballenar Jul 12 '14 at 1:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.