How to load a block programmatically and use in twig file



Add the following code in right preprocess in the .theme file.

$block = Block::load('test_block');
$variables['test_block'] = \Drupal::entityTypeManager()
->getViewBuilder('block')
->view($block);
Now in your twig file you print test block in following way {{ test_block }}.


Comments

Popular posts from this blog

Create a custom Drupal 8 module

Create Multisite using single codebase and single Database