Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-12T01:54:29.060Z
Answers.Text: I thought I had, I think my internet connection glitched when I did. Thanks for letting me know!
Answers.UserDisplayName: cballenar
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-12T01:55:00.717Z
Answers.Text: Oh, wait... No. I can do it in 14 hours :P
Answers.UserDisplayName: cballenar
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-10T16:10:27.550Z
Answers.LastActivityDate: 2014-07-12T01:16:06.630Z
Answers.LastEditDate: 2014-07-12T01:16:06.630Z
Answers.UserDisplayName: cballenar
Body: <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>
  
Tags: <entries><templating><forloop>
Title: How do you return a message if no entries are found?
ThreadText: # 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 %}
      <p>No entries found.</p>
  {% 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.
  
  ```
  <ul>
      {% for user in users %}
          <li>{{ user.username|e }}</li>
      {% else %}
          <li><em>no user found</em></li>
      {% endfor %}
  </ul>
  
  ```
  
  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  
  
  ---
  
  