In the early days of Drupal 8 we used the EntityTypeManager to render some plugin blocks or other entities. But this changed a bit, EntityTypeManager got deprecated. Here's a snippet on how to render a block inside your twig files.  In my mytheme.theme file I use the following:

/**
 * Implements hook_preprocess_node().
 */
function mytheme_preprocess_node(&$variables) {
  // Display the breadcrumb nicely in the node
  $block = \Drupal\block\Entity\Block::load('mywebsite_breadcrumbs')->getPlugin()->build();
  $variables['breadcrumbs'] = $block;
}

Now, inside my node--article--full.html.twig I can use:

{{ breadcrumbs }}

 


Saved you some valuable time?

Donate and get more free time-saving code on this website in the future.