0

I successfully place block with twig_teak module programmatically in my twig file. Unfortunately in order for this to work, it needs a region in the UI. How should I hide it from its original region? I'm placing it with code, so I don't want it showing up in any region, and disabling it removes it everywhere. Styling the unwanted one out on the front end is hopefully not the recommended solution here.

1
  • 3
    For similar scenarios in the past I've added a No render region and place blocks in there. And then obviously don't render the region :)
    – Clive
    Commented Jun 6, 2022 at 19:23

1 Answer 1

3

Block configuration entities need a region, but not blocks in general. Twig Tweak can generate the block config on the fly and doesn't need them to be stored in the database:

{{ drupal_block('plugin_id', {label: 'Example'|t, some_setting: 'example', setting_array: {value: value}}) }}

If you don't know the plugin and the settings, configure a block in UI temporarily and export the YAML file (/admin/config/development/configuration/single/export). You find both near the end of the file.

https://git.drupalcode.org/project/twig_tweak/-/blob/3.x/docs/blocks.md#block-plugin

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.