I have a page I’m generating in a module. I’m using this code to get a block from a view:
$block = views_embed_view('testimonials', 'block_1'); $view = Drupal::service('renderer')->render($block); $my_block = $view->__toString();
and display it in the generated HTML:
When I view the page in a browser and inspect it (with twig.debug=true), I don’t see the output rendered by a block template. If I display the block in a region by using the block layout page, I do see there is twig involved.
What do I have to do to make it use a template when I create the block in code? I think the correct answer would be to create a twig template for the entire page, and pull the block into the page template. But I’m curious if it could also be done this way.