I'm trying to override an email template of the webform module. The project is headless so we don't have a custom theme, and we'd like to stick with the Adminimal contrib theme. However, we do have a custom module named app in web/modules/app.

Here are the default template suggestions shown in the email source:

<!-- THEME DEBUG -->
<!-- THEME HOOK: 'webform_email_html' -->
   * webform-email-html--contact--email--email-notification.html.twig
   * webform-email-html--contact--email.html.twig
   * webform-email-html--contact.html.twig
   x webform-email-html.html.twig
<!-- BEGIN OUTPUT from 'modules/contrib/webform/templates/webform-email-html.html.twig' -->

If I just create a web/modules/app/templates/webform-email-html.html.twig file (or any of the other suggestions), the template override doesn't work: the template of the webform module is used.

1 Answer 1


The only way I found to get template override to work is to:

  1. add a template suggestion:
    // in web/modules/app/app.module
    function app_theme_suggestions_alter(array &$suggestions, array $variables, $hook) {
      $suggestions[] = $hook . '--' . 'custom';
  2. force the template used to render the webform_email_html--custom template suggestion:
    // in web/modules/app/app.module
    function app_theme($existing, $type, $theme, $path) {
      return [
        'webform_email_html--custom' => [
          'template' => 'webform-email-html--custom',
  3. create the web/modules/app/templates/webform-email-html.html.twig file

I'm not marking this answer as accepted on purpose: please tell me there's a better way, this feels overly complicated!

  • 1
    This is working as intented. Themes override module templates out of the box, module do not override templates. (And should not do this out of the box to avoid collisions. There is only one active theme, but potentially hunders of active modules.)
    – Hudri
    Nov 22, 2022 at 12:06
  • 3
    Please tell me there's a better way ... There is not, and this is pretty common, see for example the core comment module overriding a template of the field module which then can be overridden again by a theme. But you need to append __custom instead of --custom and define the base hook instead of the template name 'base hook' => 'webform_email_html',. You need the base hook to include the preprocess handlers of the base template and you don't need the template name because this is already defined by the hook name.
    – 4uk4
    Nov 22, 2022 at 12:48

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.