0

We need to display a computed summary of submitted information on both the submission preview page and in e-mails that are sent out.

I'd expect this is a common usecase and wanted to check if i'm missing something obvious before cobbling something together (and documenting that and leading others astray!)— like figuring out if computed twig elements can be excluded from the original form, and if the same computed twig elements can be pulled into the email handler easily.

2
  • OK, correction, preview page is different from confirmation page. I want the preview page— where people 'confirm' their submission before final submission, not where the site 'confirms' that they submitted.
    – mlncn
    Commented Mar 24, 2021 at 20:14
  • Frustratingly, the message on the preview page is just a regular Drupal status message, not the more customizable webform-provided confirmation message. Likewise, the template for the preview page and the input page are both like this: ``` FILE NAME SUGGESTIONS: * webform-submission-form--webform-10152.html.twig x webform-submission-form.html.twig ```
    – mlncn
    Commented Mar 24, 2021 at 20:17

1 Answer 1

0

It's not the way i'd prefer to do it, but as far as putting customization on the preview page, there is at least an alternate template available for that:

 FILE NAME SUGGESTIONS:
   * webform-submission-data--preview.html.twig
   * webform-submission-data--webform-10152--preview.html.twig
   * webform-submission-data--webform-10152.html.twig
   x webform-submission-data.html.twig

Rather than use the overall template above, we decided to do most of the work in a preprocess function for a key element on the webform. This only affects the preview page, as it's about the HTML display not the form element.

function example_preprocess_webform_element_base_html__example_element__specific_instance(&$vars) {
  $rows = example_summary($vars['webform_submission']);
  $vars['table_summary'] = [
   '#type' => 'table',  
   '#rows' => $rows,
  ];
}

We can take the {{ table_summary }} variable we added there and include it in the custom template for that element, webform-element-base-html--example-element--specific-instance.html.twig.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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