1

The template provided by the Webform module for theming a submission is rather plain. Basically, it looks like a print_r of the data variable. If you try to add HTML to validation function before it gets submitted, the HTML just gets rendered as plain text.

So I was trying to find a way to override the template from a module as opposed to a theme. I'm not able to find much documentation for this right now.

How do I override webform's default submission HTML template from a module?

0

Create a custom module and in the custom.module file add this code:

/**
 * Implements hook_theme_registry_alter
 */
function custom_theme_registry_alter(&$theme_registry) {
  $theme_registry['webform_submission_html']['path'] = drupal_get_path('module', 'custom') . '/templates';
  $theme_registry['webform_submission_html']['template'] = 'custom-submission-html';
}

You should have in the custom module your template at the location custom/templates/custom-submission-html.html.twig

The contents of that Twig file look like this.

{{ data }}
{{ data.r }}
{{ data.n }}

You can add HTML that suits your specific case.

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.