## Drupal 7
If you want to embed the contents of a block into a node, a custom block, custom module, or a page template, you can use the following snippets in the template file in which you wish your block to appear:
```
$block = module_invoke('module_name', 'block_view', 'block_delta');
print render($block['content']);
```
To specify which block from which module, you simply edit the two following variables in the first line:
'module_name' = The machine name of the module (i.e. the module's folder name). This is true for core modules too, so for instance 'search', 'user' and 'comment' would all work here.
'block_delta' = The machine name of the block. You can determine what this is by visiting the block administration page and editing the block. The URL for editing a webform block, for instance, would be something like:
Drupal 7: admin/structure/block/manage/webform/client-block-11/configure
In this example, 'client-block-11' contains the block's delta, '11'.
Custom blocks will have module name of 'block' and a number for a delta, which you can also find by editing the block.
#### Example:
```
<?php $corpwatch_searchblock = module_invoke('searchblock', 'block_view', '0'); ?>
<?php print render($corpwatch_searchblock['content']); ?>
```
[Nice writeup](https://www.drupal.org/node/26502)
## Drupal 8
In themename.theme:
```
function hook_preprocess_thingie {
$block = \Drupal\block\Entity\Block::load('your_block_id');
$variables['block_output'] = \Drupal::entityTypeManager()
->getViewBuilder('block')
->view($block);
}
```
Where "thingie" is node or page or wherever you want to use your block
Then in your twig file, just call {{ block_output }}
#### Example:
```
function essentialaccess_preprocess_node(&$variables) {
$how_to_apply_block = \Drupal\block\Entity\Block::load('howtoapply');
$variables['how_to_apply_block'] = \Drupal::entityTypeManager()
->getViewBuilder('block')
->view($how_to_apply_block);
}
```
Then in my twig file, I called `{{ how_to_apply_block }}`
[original](https://drupal.stackexchange.com/questions/153184/programatically-render-a-block-in-a-twig-template)