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 !='' %}
  <div class="something">
    {% for entry in blog %}
    {% endfor %}
{% endif %}

1 Answer 1


Your blog variable is an ElementCriteriaModel, which can be treated like an iterable array:

{% if blog|length %}
{% endif %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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