0

I have programmatically created a block. In my module folder I added all suggested templates in a templates folder(mymodule/templates/suggestedtemplatename.html.twig).

However the block is not using any of them! I have enabled the theme debugger which gives me all the suggestions and describes which part of the page is produced from which template. I can see only block.html.twig producing html. I tried drush cr and uninstalling/installing the module

  • block.html.twig is used for every block and you usually don't change it. What you are trying to do is probably to render the content inside with custom templates. But they would not replace the block twig, but would appear inside of it. – 4k4 Aug 8 '16 at 10:00
0

I was missing the implementation of hook_theme. In order to use the template you need to declare it there. FX

/**
 * Implements hook_theme().
*/
function mymodule_theme() {
  return array(
    'block__newsletter' => array(
      'render element' => 'elements',
    ),
  );
}

You should then have a templates/block--newsletter.html.twig.

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.