Drupal8: Set block in a region programmatically.

This CodeLet will display a block content in a region programmatically.
You have to implement hook_preprocess_HOOK() in THEMENAME.theme file of your theme directory.


* Implements hook_preprocess_HOOK() for HTML document templates.
* Add block in a region.

function THEMENAME_preprocess_html(&$variables) {

$block = \Drupal\block\Entity\Block::load('YOUR_BLOCK_ID');
$block_content = \Drupal::entityManager()

$variables['page']['YOUR REGION'][] = $block_content;

By saru1683 on Mon, 04/01/2016 - 10:10am

Add comment

Log in or register to post comments