Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: Entity Usage 5.0.0 Major update available for module entity_usage (5.0.0). Release: Entity Usage 8.x-2.3 Minor update available for module entity_usage (8.x-2.3). Release: Excel Serialization 2.2.0 Minor update available for module xls_serialization (2.2.0). Release: TMGMT DeepL Integration 2.4.2 Minor update available for module tmgmt_deepl (2.4.2). Release: Disable Login Page 1.2.0 Minor update available for module disable_login (1.2.0). Release: Akamai 5.1.1 Minor update available for module akamai (5.1.1). Release: GraphQL 5.1.0 Minor update available for module graphql (5.1.0). Release: Charts Plotly 1.0.5 Minor update available for module charts_plotly (1.0.5). Module Revived: Two-factor Authentication (TFA) 8.x-1.13 Module tfa updated after 10 months of inactivity (8.x-1.13). Usage Milestone: Easy Email Module easy_email crossed 10,000 active installs.

Twig Real Content - empty region / content check helper

2,691 sites Security covered Drupal 9–11

Part of the Twig ecosystem · 26 projects

View on drupal.org

This module provides a Twig filter and test to determine if a rendered variable, such as a region, contains meaningful content. It helps prevent outputting empty wrappers and simplifies checks for actual content within Twig templates.

Provides a "real_content" twig filter and test to determine if a certain twig variable (typically a region) has meaningful content is empty. Read the super long core issue for details.

Core issue

#953034: [meta] Themes improperly check renderable arrays when determining visibility
Once the core issue is solved (which we guess will not be soon, if ever, due to logical problems), this module may become obsolete.

TL;DR

If you need to check if a region is empty in twig, for example to not output the wrappers at all, this module is what you want, and the core issue describes the reasons why this is so complicated.

Functionality & how to use

As Twig filter:

Adds a |real_content twig filter to run on rendered variables, which filters out all wrappers and trims the code to check if there is real content.

{% set sidebar_first_rendered = page.sidebar_first|render %}
{% if sidebar_first_rendered|real_content is not empty %}
  <div class="sidebar sidebar--first">
    {{ sidebar_first_rendered }}
  </div>
{% endif %}

Without this module, it would be something like this:

{% set sidebar_first_rendered = page.sidebar_first|render %}
{% if sidebar_first_rendered|striptags('<drupal-render-placeholder><img><video><[...]>')|trim is not empty %}
  <div class="sidebar sidebar--first">
    {{ sidebar_first_rendered }}
  </div>
{% endif %}

As Twig Test:

Adds an
is real_content twig test to run on rendered variables, which filters out all wrappers and trims the code to check if there is real content. Returns TRUE if there is real content, else FALSE.

{% set sidebar_first_rendered = page.sidebar_first|render %}
{% if sidebar_first_rendered is real_content %}
  <div class="sidebar sidebar--first">
    {{ sidebar_first_rendered }}
  </div>
{% endif %}

With Twig Blocks:

Inherited Twig blocks are already rendered, so you can do:

{% extend 'paragraphs.html.twig' %}
{% block paragraph %}
  {% if parent() is real_content %}
    {{ parent() }}
  {% endif %}
{% endblock paragraph %}

Unstripped DOM elements

The following HTML elements are not being stripped, as they typically have no own DOM text content. If they are present, they are treated as existing content.

[
    '<drupal-render-placeholder>',
    '<embed>',
    '<hr>',
    '<iframe>',
    '<img>',
    '<input>',
    '<link>',
    '<object>',
    '<script>',
    '<source>',
    '<style>',
    '<svg>',
    '<video>',
];

Please create an issue, if further exclusions are required. We're also discussing to put this into config here: #3293420: Make allowed tags configurable

Render arrays and performance

As rendering a render array multiple times has negative impact on performance, we decided to disallow running this on (unrendered) render arrays directly.
Perhaps someone is interested to implement this: #3293416: Allow on render arrays and combine with isEmpty()

Related

Related modules

Related discussions & blog posts

Supporting this module

Support DROWL's ♥ FOSS work on this module on OpenCollective!

Drupal and this module are FOSS. However, it takes dedicated people to develop and maintain. And they need YOU to give back!

We're committed to building and maintaining Drupal modules that benefit the entire community.

Supporting us on OpenCollective helps us continue to improve, innovate and contribute to Drupal's future. Every pledge makes a difference!

If this module has helped you, we would be very grateful for your donation to support its further development and maintenance.

Support our FOSS development ♥️

You can also speed up the development of features or bugfixes you'd love to see, by sponsoring and giving back!

Sponsor a feature or bugfix 🚀

Let's make Drupal even better, together!

Development proudly sponsored by German Drupal Friends & Companies:

webks: websolutions kept simple (https://www.webks.de)
and
DROWL: Drupalbasierte Lösungen aus Ostwestfalen-Lippe (OWL), Germany (https://www.drowl.de)

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

2 tracked projects depend on this one

Activity

Tracked releases
1
Tracked since
Mar 2026
Latest release
5 months ago
Releases (12 mo)
1 ▲ from 0
Maintenance
Active

Releases

Version Type Core Release date
1.0.3 Stable 9–11 Mar 19, 2026