0

I want render my custom block in template file, but what I get is the block without going through the twig file.

theme_preprocess_page(&$variables) { 

    $block =  \Drupal::service('plugin.manager.block')->createInstance('id_custom_block', array());
    $variables['custom_block'] = $block->build();

}

I Want render custom block, and different from a view block, this not work:

$block = \Drupal\block\Entity\Block::load('your_block_id');
$variables['block_output'] = \Drupal::entityTypeManager()
->getViewBuilder('block')
->view($block);

Am I doing something wrong?

2
  • Did you replace your_block_id with the actual ID name? Did you clear/flush the cache?
    – No Sssweat
    Sep 9, 2016 at 8:04
  • of course man !!
    – BOES
    Sep 9, 2016 at 8:55

0

Browse other questions tagged or ask your own question.