<p>Your blog variable is an <a href="https://craftcms.com/docs/templating/elementcriteriamodel" rel="nofollow">ElementCriteriaModel</a>, which can be treated like an iterable array:</p>

<pre><code>{% if blog|length %}
    Content
{% endif %}
</code></pre>

CC BY-SA 3.0
2016-05-28T17:05:36.250Z
2016-05-28T20:36:18.027Z
2016-05-28T20:36:18.027Z
Patrick Harrington
<p>I've got a blog section on a page but want to hide it if there are no blogs. </p>

<pre><code>{% set blog = craft.entries.section('blog').limit(5) %}
{% if blog !='' %}
  &lt;div class="something"&gt;
    {% for entry in blog %}
      ...
    {% endfor %}
  &lt;/div&gt;
{% endif %}
</code></pre>

<templating><conditional>
How do I write a conditional for whether a section contains entries?
# How do I write a conditional for whether a section contains entries?

(Asked by: username_0 on 2016-05-28)

I've got a blog section on a page but want to hide it if there are no blogs. 
{% set blog = craft.entries.section('blog').limit(5) %}
{% if blog !='' %}
  
    {% for entry in blog %}
      ...
    {% endfor %}
  
{% endif %}

**Tags:** templating, conditional

---

## 1 answers

### Answer by username_1 on 2016-05-28. Score: 6 | Accepted answer

Your blog variable is an ElementCriteriaModel, which can be treated like an iterable array:
{% if blog|length %}
    Content
{% endif %}


---

