phpdrupaldrupal-8

Drupal 8 Delete layout prefix


I have a page, created via page manager with the layout type - "One Column". I placed blocks on the page and when I open this page, I see my blocks wrapped by a

<div class="block-region-content">

When I print content variable in twig template, I can see that this div is the value of #prefix property

content array(12)
   'content' => array(4)
      '#prefix' => string(34) "<div class="block-region-content">"
      '#suffix' => string(6) "</div>"

How can I delete this properties?


Solution

  • You can implement hook_preprocess_HOOK to achieve this. For example, you should probably preprocess blocks within your theme (same can be done from a module though) :

    function THEME_preprocess_block(&$vars) {
      // Act on a specific block, eg. here the page title block 
      if ($vars['plugin_id'] === 'page_title_block') {
        unset ($vars['content']['#prefix'], $vars['content']['#suffix']);
      }  
    }