Blog IT

There are various ways you can add blocks to regions in pages in Drupal. You could add it in the block interface, use Panels or Context. But what if you just want to place a block directly in a Twig template?

The simplest way to place a block in a Twig template is to use the Twig Tweak module. Twig Tweak is a very handy module that gives you a range of functions to make theming with Twig easier.

Install Twig Tweak

Go ahead and install the Twig Template module. You can download it with composer and enable it with Drush:

  composer require drupal/twig_tweak

And enable with Drush:

drush en twig_tweak

Now that you have the ID for the block, the next step is to place the block in the Twig template with the drupal_block() function.

{{ drupal_block('blockid') }}