You are looking at the old Apostrophe 0.5 documentation. It is deprecated for new projects. Check out the latest version!

Detecting empty areas and singletons

← Previous: Accessing images and files directly

It's common to want to do something special if an area or singleton is empty, especially if the user does not have editing privileges for the current page. You can detect that with a little Nunjucks logic:

{% if (not edit) and aposSingletonIsEmpty(page, 'singletonName', 'video') %}
  <p>A default placeholder video might go here</p>
{% endif %}

"Why does it take an area property if it's a singleton?" Under the hood, singletons and areas are stored in the same way.

aposAreaIsEmpty is also available:

{% if (not edit) and aposAreaIsEmpty(page, 'areaName') %}
  <p>Whoops, someone is a very lazy editor!</p>
{% endif %}

Next: Working with lockups →