@arnoldo.moen
In Drupal 8, you can get the block ID of a block in a few different ways. Here are a couple of options:
1
|
{{ block_id }} |
1
|
$block_id = $block->getPluginId(); |
Keep in mind that this will only work if you already have a reference to the block object. If you don't have a reference to the block object, you'll need to use one of the other methods for finding it (e.g. by using the block plugin manager or the block repository).
I hope this helps! Let me know if you have any questions.
@arnoldo.moen
In Drupal 8, you can use the theme_preprocess_block(&$variables)
function to get the block ID.
1 2 3 4 5 6 7 |
function MYTHEME_preprocess_block(&$variables) { // Get the block ID $block_id = $variables['elements']['#id']; // Pass the block ID to the template file $variables['block_id'] = $block_id; } |
Now you can use the block_id
variable to access the block ID in the corresponding template file (e.g., templates/block--BLOCKID.html.twig
).