Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

Twig Block by id

No security coverage Maintenance fixes only 19 sites

Part of the Twig ecosystem · 43 projects

This module adds a Twig function that allows you to easily render a block in your theme using its configuration ID. It simplifies the process compared to other methods, directly enabling the use of block instance IDs and automatically applying existing block configurations.

This module simply provides a drupal_block_by_id() twig function to render a block in a theme, by configuration id.

{{ drupal_block_by_id('my_block_id') }}

Features

Twig Tweak module provides a drupal_block() function, which requires the plugin value to be identified, apart from the configuration id. When using custom blocks, this is not easy to identify, it's not in the UI, and it is a large alpha-numeric number, like 'block_content:e701a91b-419f-48fc-9b48-136138eaebec'. Apart, you would need to define all the configuration manually, as the second parameter, instead of using the configuration set in the block instance in Block Layout page.

To makes things easier, this module provides just a drupal_block_by_id() function that takes only the block instance id instead of the plugin id, and applies the block configuration by default, allowing to override those settings as second parameter. It uses Twig Tweak module's drupal_block() function internally.

Twig Tweak module also provides a drupal_entity() function that could be used with blocks. However the rendering process is different, and we have run into cases where it bypasses the cache contexts and the new content is not displayed where saving after editing the block in the UI, requiring a cache clear. Using drupal_block_by_id() you won't run into that problem.

Additional Requirements

Twig Tweak

Drupal 9–11

Ask your assistant about Twig Block by id

Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works

Depends on

Dependencies of the latest stable release

  • twig_tweak Drupal core

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
3
Tracked since
Aug 2023
Latest release
1 year ago
Releases (12 mo)
0 ▼ from 1
Maintenance
Slowing

Release Timeline

Releases

Version Type Core PHP Release date
1.0.2 Stable 9–11 Jan 31, 2025
1.0.1 Stable 9–10 Jan 16, 2024
1.0.0 Stable 9–10 Aug 25, 2023