Skip to content
Twig Field Finder
Theme

Check if field is empty

Fill in your field name

Italic values are placeholders: replace them with your own machine names, or let the builder do it.

Reads the entity directly, before field formatters run.

  1. Twig
    {% if not node.field_name.isEmpty() %}
      {{ content.field_name }}
    {% endif %}

Reads the content render array, after field formatters run.

  1. Twig
    {% set content_render = content.field_name|render %}
    {% if content_render|trim %}
      {{ content_render }}
    {% endif %}

Gotcha

Use the render-and-trim pattern when isEmpty() is not reliable (e.g. field present but formatter outputs nothing). It avoids rendering the field twice.