I have an application that is two parts: a website front-end and a restful back-end I can do with AngularJS.
The restful part is done by a module and I need to override html.html.twig.

How do I achieve this?

  • 1
    Not that this isn't a good question, but do you really need to override the template in the first place? I imagine you're wanting to stick an attribute on the body tag or something like that? That can be done with a preprocess, and most other things probably can too
    – Clive
    Dec 2 '15 at 18:26
  • No, I want to render the body of an angularjs app which is different from the content of html.html.wig Dec 2 '15 at 19:41
  • You can't (and if you can, then you shouldn't), overriding templates is the job of the theme. PS> the html.html.twig is overridden by most base themes so your changes will be overridden as well.
    – Eyal
    Dec 2 '15 at 20:57
  • For writing an Angular app the standard procedure wouldn't be as effective as a headless Drupal sending all data to the client via REST
    – alexej_d
    Dec 2 '15 at 22:33
  • @alexej_d I want just to send the first page css, js loaders for angularjs Dec 2 '15 at 22:36

Overriding templates in the modules is not suggested because Drupals architecture doesn't really support multiple modules overriding same template.

However if you are still willing to do this, you have to simply add hook_theme() like this in your module file:

 * Implements hook_theme().
function modulename_theme() {
  return [
    // Normally theme suggestion templates are only picked up when they are in
    // themes. We explicitly define theme suggestions here so that these
    // templates in this module are picked.
    'html' => array(
    'render element' => 'elements',
    'base hook' => 'html',

Note: This will cause error messages in case you don't have the html.html.twig template available in the templates folder.

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.