Drupal 8

Manually loop through blocks in a region.html.twig

UPDATE 2: It turns out that the elements array is not reliable available. So i've decided to put the .row wrapper in the region.html.twig and add the cell classes per region in the .theme file. This kinda sucks, but i currently see no other way to ensure the cell / column classes are added in a specific region.

$variables['block_region'] = $block->getRegion();
// Define block wrappers per region
if($variables['block_region'] == 'header'){
    $variables['attributes']['class'][] = 'cell';
    $variables['attributes']['class'][] = 'shrink';

You can also archive this manually by using fences for blocks. But if you or someone else forget to add the class, it will rseult in layout issues.

UPDATE: Don't do this. This causes an error, blocks randomly not printed out till you clear the drupal cache again. I will do further research on this later.

Subscribe to RSS - Drupal 8