0

I installed the module "Shariff Social Media Buttons" for "Drupal 8" :

https://www.drupal.org/project/shariff

This module once installed, add a block in :

/admin/structure/block

I want to display this block in a template :

https://www.drupal.org/docs/8/modules/twig-tweak/rendering-blocks-with-twig-tweak

I tried with the following code :

{{ drupal_entity('block', shariffsharebuttons) }}

But the block does not work (it is not rendered on my page)

enter image description here

enter image description here

drush ev 'print_r(\Drupal::configFactory()->listAll("block.block."));'

enter image description here

  • 2
    Just a wild guess, but: try using quotes around the block name {{ drupal_entity('block', 'shariffsharebuttons') }} – Hudri Nov 27 '18 at 19:35
  • @Hudri Yes that's right. Thank you. Drupal documentation is not correct – user90656 Nov 27 '18 at 19:44
  • shariffsharebuttons without quotes is a variable (which content is most likely empty, why you didn't get any result), while 'shariffsharebuttons' is a constant / a string value. The doc is not really wrong, they just didn't explain the Twig syntax. – Hudri Nov 27 '18 at 19:50
  • Docs seem to be correct. They also suggest {{ drupal_block('system_breadcrumb_block') }}. And they explicitly say: Note that the plugin_id needs to be wrapped in quotes. – leymannx Nov 27 '18 at 19:57
1

you can use Twig Tweak Module, will gives you twig extension called drupal_blockand you can render your block like the following :

{{ drupal_block('shariff_block') }}

Take a look to the module Cheat sheet for more info.

Note : Shariff Module provide block with the id shariff_block not shariffsharebuttons.

  • Any idea about doing this without installing new module? – Mohsin Saeed Nov 6 '19 at 16:14