I have created a block in custom block library, i need to render the block on all pages except home page.

Unfortunately I need to do it in twig file only because of ui issues if I enabled in the block layout UI

In twig file how can I render the block in drupal 8.



Add following code in "themename.theme"

function themename_preprocess_page(&$variables) {
  $block = \Drupal\block\Entity\Block::load('block_id');
  $block_content = \Drupal::entityTypeManager()
 $variables['your_block_name'] = $block_content;

in twig template file use following variable

{{ your_block_name }}
|improve this answer|||||
  • Note that this will make the variable your_block_name available in the page.html.twig . For other template files use the appropriate preprocess hook. E.g. theme_preprocess_node for node.html.twig files – batigolix Jun 14 '18 at 9:29

Not the answer you're looking for? Browse other questions tagged or ask your own question.