Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Steps to repeat:
- Install a vanila D8 site
- Create a default view and literally keep the defaults
- Add a view block with the defaults still
- Under the ADVANCED pane, set Hide block if the view output is empty to Yes
- Save the view
- Go to Structure > Block Layout
- Place the block that you have created in the Sidebar Second region. This view block will also be the only one in this region
- Go to the site's homepage
Screenshot of the Views block configuration:
Expected Result:
The empty view block which was specified to not be displayed when it's empty should not trigger the region to be rendered.
Actual Result:
The empty view block caused page.html.twig's ` if page.second_sidebar
` condition to be evaluated as TRUE with literally nothing inside it at all like:
Comment | File | Size | Author |
---|---|---|---|
drupal-core-views-block-sidebar-trigger.jpg | 483.28 KB | leolandotan | |
drupal-core-views-block-configuration.png | 326.08 KB | leolandotan |
Comments
Comment #2
LendudeThis is a known issue that stems from outside Views (Views is just the most likely place you will run into this)
see #953034: [meta] Themes improperly check renderable arrays when determining visibility
and #2685157: Empty region rendered when a Views block with no results and 'block_hide_empty' set is in the region
Comment #3
timhtheosHi @leolando.tan,
In your case, the view itself didn't render. If you want the region not to render itself if it is empty, try to pipe your condition to
| render
. Your{% if page.second_sidebar %}
should be{% if page.second_sidebar | render %}
.Comment #4
leolandotan CreditAttribution: leolandotan as a volunteer and at Promet Source commentedHi @Lendude and @timhtheos, thank you very much for your responses! Your explanations and solutions really helped me. This looks like a quite serious issue.
Comment #5
mindhunter75 CreditAttribution: mindhunter75 commentedI ran into the same problem. I tried the "| render" options.
The sidebar is empty, but then the bootstrap grids don't match the 12cols anymore.
Normal with no sidebar i have:
9col - 3col.
But now i have
6col - 3col ....
So i have a space in my theme.
Does anyone have a solution? I use the Bootstrap theme.
Thank you in advance.
Comment #6
jwilson3Cross-post from #2443457. Just following up here that the current workaround until #953034: [meta] Themes improperly check renderable arrays when determining visibility lands is to first render the output of the region the block is placed in to determine whether it is empty or not by stripping out the rendered tags.
Eg. in page.html.twig in your theme:
Comment #7
jwilson3Comment #8
jwilson3