class RenderBlock in Twig Blocks 8
Adds extension to render a block.
Hierarchy
- class \Drupal\twig_blocks\Twig\RenderBlock extends \Drupal\twig_blocks\Twig\Twig_Extension
Expanded class hierarchy of RenderBlock
1 string reference to 'RenderBlock'
1 service uses RenderBlock
File
- src/
Twig/ RenderBlock.php, line 13 - Contains \Drupal\twig_blocks\Twig\RenderBlock.
Namespace
Drupal\twig_blocks\TwigView source
class RenderBlock extends \Twig_Extension {
/**
* {@inheritdoc}
*/
public function getName() {
return 'render_block';
}
/**
* {@inheritdoc}
*/
public function getFunctions() {
return [
new \Twig_SimpleFunction('render_block', [
$this,
'render_block',
], [
'is_safe' => [
'html',
],
]),
];
}
/**
* Provides function to programmatically rendering a block.
*
* @param string $block_id The machine id of the block to render.
*/
public function render_block($block_id) {
$block = \Drupal\block\Entity\Block::load($block_id);
$markup = \Drupal::entityTypeManager()
->getViewBuilder('block')
->view($block);
return [
'#markup' => drupal_render($markup),
];
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RenderBlock:: |
public | function | ||
RenderBlock:: |
public | function | ||
RenderBlock:: |
public | function | Provides function to programmatically rendering a block. |