Drupal is a registered trademark of Dries Buytaert
ai 1.3.1 Minor update available for module ai (1.3.1). seven 2.0.0-beta6 New beta version released for theme seven (2.0.0-beta6). seven 1.0.1-beta1 First beta version released for theme seven (1.0.1-beta1). ai_provider_anthropic 1.2.2 Minor update available for module ai_provider_anthropic (1.2.2). acquia_dam 1.1.13 Minor update available for module acquia_dam (1.1.13). media_duplicates 2.0.4 Minor update available for module media_duplicates (2.0.4). eca 3.1.0-beta2 New beta version released for module eca (3.1.0-beta2). swiper_formatter 2.1.1 Minor update available for module swiper_formatter (2.1.1). solo 1.0.31 Minor update available for theme solo (1.0.31). raven 7.3.7 Minor update available for module raven (7.3.7). commercetools 2.2.0 Minor update available for module commercetools (2.2.0). erfo 1.0.1 Minor update available for module erfo (1.0.1). gcds 1.0.1 Minor update available for theme gcds (1.0.1). erfo 1.0.2 Minor update available for module erfo (1.0.2). ervms 1.0.2 Minor update available for module ervms (1.0.2). ervms 1.0.3 Minor update available for module ervms (1.0.3). media_acquiadam 2.1.5 Minor update available for module media_acquiadam (2.1.5). simple_account_policy 1.0.11 Minor update available for module simple_account_policy (1.0.11). drowl_layouts_bs 1.0.12 Minor update available for module drowl_layouts_bs (1.0.12). container_query_images 1.0.2 Minor update available for module container_query_images (1.0.2).

twig_real_content

3,192 sites Security covered
View on drupal.org

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)

Activity

Total releases
1
First release
Mar 2026
Latest release
14 hours ago
Release cadence
Stability
100% stable

Releases

Version Type Release date
1.0.3 Stable Mar 19, 2026