How-to library · Developer docs

How-to library

Task-shaped pages: a title that starts with a verb, the situation in a few lines, the steps, the working code in both engines, and why this way rather than another. Found from a search, done, and left.

How-to Images

Stop a grey placeholder appearing on production

The placeholder appears for signed-in users by default, and a site member counts as signed in. Either set Show image placeholders to Never on a site with member accounts, or use getAreaImage() with an isBlank() check in templates members see.

Context

Context. getAreaImageOrPlaceholder() returns a generated grey image of the requested size when the layout area is empty, so authors can see where an image is missing. Whether it appears is the site setting Show image placeholders: For logged in users (the default), Always, or Never. "Logged in" means any account, including a site member. On a membership site, every signed-in member sees grey boxes wherever an author left an image empty, which is the usual report.

Steps

  1. Confirm the cause: sign in as a member on production and look; sign out and the box is gone.
  2. On a site with member accounts, set Show image placeholders to Never.
  3. Or keep the setting and stop using the placeholder getter in templates members can see: use getAreaImage() and render nothing when it is blank.
  4. Keep the placeholder getter for admin-only previews and for layouts authors are still filling.

Template code

Template code
{* shows a placeholder to anyone signed in, members included, under the default setting *}
{$component->getAreaImageOrPlaceholder('image', 800, 450)->getHtml()}

{* shows nothing when empty, for everyone *}
{$image = $component->getAreaImage('image')}
{if !$image->isBlank()}{$image->getResized(800, 450, 'fit')->getHtml()}{/if}
{{ component.getAreaImageOrPlaceholder('image', 800, 450).getHtml() }}

{% set image = component.getAreaImage('image') %}
{% if image is not empty %}{{ image.getResized(800, 450, 'fit').getHtml() }}{% endif %}

Why this and not that

Not hiding placeholders with CSS: the file is still requested, and the class is not on the element. Not deleting the empty areas: the box marks content an author has not supplied yet, which is information; what to change is who sees it. A placeholder is a real file, created on first request for each new size under placeholders/ in the file manager, so a template asking for many sizes fills the folder.

Go deeper

Was this page helpful?

Your answer goes to the docs team.