Sidebars do not show unless blocks render some text.

Created on 10 April 2024, 3 months ago
Updated 4 June 2024, 24 days ago

I've not tested this on the 6.x branch but the code seems to be the same.

Problem/Motivation

commit 4c6e9efcc6a41625971915e70ffd3aa605a25cfc "fix issues with empty regions rendering"
changed how empty regions were detected. The new test is to use the following twig filters:
render|striptags|trim
This works unless the result of render returns html tags without any text content - that when rendered on the page result in content being displayed. Consider the case of an img tag, or the search form - which out of the box in Drupal 10 if the title is set not to display has no text content - just html that is then styled with CSS.

Steps to reproduce

create a new drupal site, add dxpr or use one you have already.

Set blocks up such that there is one block in either the sidebar_first "Primary" or sidebar_second "Secondary" regions. This block can be either a custom block with just an image in it. Or just add the search form. Make sure you don't display the title.

View a node. See that the block and region are not rendered. go back and edit the form or custom block and set the title to display (or add some text to the custom block) save and then reload the node. See that the block/region now render.

Add some CSS to hide the title using display none. See that the block/region is still rendered.

Proposed resolution

Either revert the above commit - or probably we need to work out a better solution to detecting if there is any content. Perhaps removing the strip_tags?

The real problem here is you will never be able to tell if the region is actually empty without rendering the content then considering the impact of the css - this cannot be done at the twig layer - and probably not at the PHP layer (I mean technically possible I assume but not something you want to do ) .

So the question then becomes what is an acceptable detection.

Is it that there is some text?
Is it that there is a block that might render something?
Is it that there is either text or a subset of html tags? i.e. if there is an img
Is it that if there is a search form that it should render?

Is a workaround to add something that will trigger the test in the block template - but not actually render on the page.

For example: Instead of not rendering the block title onto the page just hide it via CSS with display none.

If we look at how Core's Olivero and the parent Bootstrap theme hand this situation they use a test of {% if page.sidebar_first %} without the added twig rendering.

This is what existed before the referenced commit above. So perhaps just reverting this commit is a good solution. Probably would need to be done in a major version bump given this could result in changes to page layout.

🐛 Bug report
Status

Fixed

Version

6.0

Component

Code

Created by

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

Merge Requests

Comments & Activities

Production build 0.69.0 2024