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

1
  • 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.
    – 4uk4
    Aug 8, 2016 at 10:00

1 Answer 1

1

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 and acknowledge that you have read and understand our privacy policy and code of conduct.

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