Views blocks now use placeholders, making it impossible for the theme to determine if it’s empty or not

Created on 2 July 2025, about 1 month ago

Problem/Motivation

Since updating to 11.2.2 we have noticed that this code in ViewsBlockBase.php has created an issue:

  /**
   * {@inheritdoc}
   */
  public function createPlaceholder(): bool {
    return TRUE;
  }

Our issue involves a Views block, where in our twig file we are using the following filters:

render|striptags|trim|length > 0

to evaluate whether anything is to be rendered and thus render the surrounding markup to contain it. However after this addition was made the render filter now produces a <drupal-render-placeholder> element alone, so once the striptags filter is ran on that then we are left with nothing. Thus our check above evaluates to false, and our views block does not get rendered to the page even though it contains results.

If I alter the createPlaceholder() method to return FALSE then our Views block is once again rendered as expected.

Steps to reproduce

  1. Create a Views block that contains output (I believe just a title will suffice)
  2. Place the block in a region
  3. In a twig template, use the above filters on the region to see the placeholder element alone
  4. Alter the createPlaceholder() method to return FALSE
  5. Observe that the above filters now work as there is markup left after they are passed through.
πŸ› Bug report
Status

Active

Version

11.2 πŸ”₯

Component

views.module

Created by

πŸ‡¬πŸ‡§United Kingdom jonnyhocks

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

Merge Requests

Comments & Activities

  • Issue created by @jonnyhocks
  • Pipeline finished with Failed
    about 1 month ago
    Total: 421s
    #536982
  • πŸ‡¬πŸ‡§United Kingdom jonnyhocks

    I've opened a merge request just reverting the update to return false now until a solution is put forward.

  • πŸ‡¬πŸ‡§United Kingdom nicrodgers Monmouthshire, UK
  • πŸ‡³πŸ‡ΏNew Zealand quietone

    If this problem was discovered on a version of Drupal that is not 11.x, add that information in the issue summary and leave the version at 11.x. In Drupal core changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to the Core change policies β†’ . Also mentioned on the version β†’ section of the list of issue fields documentation. Thanks.

  • πŸ‡¨πŸ‡¦Canada kiwad

    I have this code in twig :

    {% set aside_start_top_rendered = page.aside_start_top|render %}
    {% set aside_start_bottom_rendered = page.aside_start_bottom|render %}

    {% set aside_exists = (aside_start_top_rendered is real_content or aside_start_bottom_rendered is real_content) and not narrow and container_type != 'fluid' %}

    After updating from 11.1.18 to 11.2.2, aside_exists now always returns TRUE because of placeholders

    Before 11.2.2, my block had this in it :

    {"cfa_navigationprincipale":{"#cache":{"keys":["entity_view","block","cfa_navigationprincipale"],"contexts":["languages:language_interface","route.menu_active_trails:main"],"tags":["block_view","config:block.block.cfa_navigationprincipale","config:system.menu.main"],"max-age":-1},"#weight":0,"#lazy_builder":["Drupal\\block\\BlockViewBuilder::lazyBuilder",["cfa_navigationprincipale","full",null]]},"#sorted":true,"#theme_wrappers":["region"],"#region":"aside_start_top"}

    After 11.2.2

     {"cfa_navigationprincipale":{"#cache":{"keys":["entity_view","block","cfa_navigationprincipale"],"contexts":["languages:language_interface","route.menu_active_trails:main"],"tags":["block_view","config:block.block.cfa_navigationprincipale","config:system.menu.main"],"max-age":-1},"#weight":0,"#lazy_builder":["Drupal\\block\\BlockViewBuilder::lazyBuilder",["cfa_navigationprincipale","full",null]],"#create_placeholder":true},"#sorted":true,"#theme_wrappers":["region"],"#region":"aside_start_top"}  
    

    As a workaround for now, I did in custom module :

    function mymodule_preprocess_page(array &$variables) {
      if (isset($variables['page']['aside_start_top']['cfa_navigationprincipale'])) {
        $variables['page']['aside_start_top']['cfa_navigationprincipale']['#create_placeholder'] = FALSE;
      }
      if (isset($variables['page']['aside_start_bottom']['cfa_navigationprincipale'])) {
        $variables['page']['aside_start_bottom']['cfa_navigationprincipale']['#create_placeholder'] = FALSE;
      }
    }
  • πŸ‡΅πŸ‡°Pakistan hamza_niazi

    I was facing the same issue but for merge 12587 works fine

  • πŸ‡ΊπŸ‡ΈUnited States pmagunia Philadelphia πŸ‡ΊπŸ‡Έ

    There are also other files this temporary fix needs to be applied to. For example:

    core/modules/system/src/Plugin/Block/SystemMenuBlock.php

Production build 0.71.5 2024