Change record status: 
Introduced in branch: 
Introduced in version: 

In Drupal 7 it was possible to specify separate block templates per region, such as block--header.tpl.php and block--footer.php to output different HTML for blocks placed in the header and footer regions. It was also possible to adjust variables based on region in hook_preprocess_block(). Both of these features have been removed.

It is suggested you use standard CSS cascading selectors to style blocks differently on different parts of the page.

Updates Done (doc team, etc.)
Online documentation: 
Not done
Theming guide: 
Not done
Module developer documentation: 
Not done
Examples project: 
Not done
Coder Review: 
Not done
Coder Upgrade: 
Not done
Other updates done


Benia’s picture

If I use CSS to hide #sidebar, in whatever theme, a wide blank block is created instead; The sidebar region keeps staying, but just as an empty and blank "box".

allan00958’s picture

I don't know if you found the answer already but maybe try this in your page.html.twig:

<div class="someClass">
    <div class="row">
        {% if page.sidebar %}
            <div class="col-12">
               {{ page.sidebar}}
        {% endif %}

Maybe add an if statement and hide the sidebar using a preprocess function.

a.milkovsky’s picture

How to make a theme hook suggestion for blocks according to region?

use Drupal\block\Entity\Block;

function MODULE_theme_suggestions_block_alter(array &$suggestions, array $variables) {
  if (!empty($variables['elements']['#id'])) {
    $block = Block::load($variables['elements']['#id']);
    $suggestions[] = 'block__' . $block->getRegion() . '__' . $variables['elements']['#id'];
  /* Use this 'else if' only if you are using page_manager module and want to know which region is the block */
  else if (isset($variables['elements']['#configuration']['region'])) {
    $suggestions[] = 'block__page_' . $variables['elements']['#configuration']['region'] . '__' . end(explode(':', $variables['elements']['#plugin_id']));
  return $suggestions;