1

I'd like to be able to print the block id/number of my custom block in its template. I feel like these must exist because Display Suite has a token for it: [block_content:id].

Like a url to edit a block is, it goes to the edit form: block/17

How do I get that 17 in the twig template? Looking in block.html.twig, I don't see anything about a block's number.

2

You find the block_content entity in the template variable elements to get the ID:

block.html.twig:

{{ elements.content['#block_content'].id() }}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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