Skip to content

Instantly share code, notes, and snippets.

@frankyonnetti
Last active May 23, 2021 16:46
Show Gist options
  • Save frankyonnetti/780aefb2d8f5592c278511afc29dca1e to your computer and use it in GitHub Desktop.
Save frankyonnetti/780aefb2d8f5592c278511afc29dca1e to your computer and use it in GitHub Desktop.
Drupal 8 - blocks #drupal8

Twig Teak Cheet Sheet Rendering blocks with Twig Tweak

Get block IDs using drush

# system blocks
vendor/bin/drush ev "print_r(array_keys(\Drupal::service('plugin.manager.block')->getDefinitions()));"

# custom blocks
vendor/bin/drush ev 'print_r(\Drupal::configFactory()->listAll("block.block."));'

# custom block IDs
vendor/bin/drush sqlq 'SELECT id, info FROM block_content_field_data'
{# system blocks #}
{{ drupal_block('menu_block:main') }}

{# custom blocks #}
{{ drupal_entity('block', 'contact_us') }}

{# custom blocks ID #}
{{ drupal_entity('block_content', 'block_content_id') }}

<div class="block">
  <h2>{{ 'Example'|t }}</h2>
  {{ drupal_entity('block_content', content_block_id) }}
</div> 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment