Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: OpenID Connect / OAuth client 3.0.0-alpha9 New alpha version released for module openid_connect (3.0.0-alpha9). Release: Timelinr 1.0.1 Minor update available for module timelinr (1.0.1). Usage Milestone: Simplify Module simplify crossed 10,000 active installs. Usage Milestone: Views Reference Filter Module entityreference_filter crossed 10,000 active installs. Usage Milestone: Dropdown Language Module dropdown_language crossed 10,000 active installs. Usage Milestone: Paragraphs Browser Module paragraphs_browser crossed 10,000 active installs. Usage Milestone: OpenAPI Module openapi crossed 10,000 active installs. Usage Milestone: Decoupled Router Module decoupled_router crossed 10,000 active installs. Usage Milestone: Time Field for Drupal 8+ Module time_field crossed 10,000 active installs. Module Revived: Entityqueue Buttons 1.1.2 Module entityqueue_buttons updated after 8 months of inactivity (1.1.2).

Twig Block by id

20 sites No security coverage Drupal 9–11 Twig ecosystem
View on drupal.org

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

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
1
Tracked since
Jan 2025
Latest release
1 year ago
Releases (12 mo)
0 ▼ from 1
Maintenance
Dormant

Releases

Version Type Core Release date
1.0.2 Stable 9–11 Jan 31, 2025