Exclude empty sections

Created on 9 July 2020, almost 4 years ago
Updated 10 October 2023, 9 months ago

Sections without content, either without a block or some other conditional rendering, always render the container/row/column. It can be especially problematic if the container has padding, margin, or background-color classes. Each section should have the option to prevent rendering if the content variable is empty.

Feature request
Status

Needs work

Version

2.0

Component

Code

Created by

🇺🇸United States robphillips

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇮🇹Italy drp_distruptor Neaples

    Applying the patch of this link 🐛 Empty layout sections get rendered Needs work for Bootstrap Layout Builder seems not to work.

    Again, all the patches attached to this issue are not applied on my Drupal 9.5.10 instance; so I found a workaround for blb-container-wrapper.html.twig template:

    {% if children|render|raw|striptags|spaceless is not empty %}
        <div {{ attributes }}>{{ children }}</div>
    {% endif %}
    
  • 🇦🇺Australia neubreed

    And if you have a carousel or images in your section, omit stripping img tags (or any other tags) with:

    {% if children|render|raw|striptags('<img>')|spaceless is not empty %}
    <section {{ attributes }}>{{ children }}</section>
    {% endif %}
    

    Otherwise the section will be considered empty

Production build 0.69.0 2024