This is further to https://www.drupal.org/project/webform/issues/2946976.
I'm trying to use a Twig template for the HTML email that is sent upon webform submission; I'm using Symfony Mailer for the HTML.
I have the twig template working, by:
- Selecting Twig template as the formatter for the email body
- Naming my twig file webform-email-message-html--WEBFORM-ID.html.twig and placing it in my theme folder.
Now I can't get the webform_submission values to appear in the rendered email. I've tried:
{{ webform_token('[webform_submission:values:field_name]', webform_submission, [], options) }}
{{ data.field_name }}
{webform_submission:values:field_name }}
I have the following code in my .module file:
function my_module_preprocess_webform_email_message_html(&$variables) {
/** @var \Drupal\webform\WebformSubmissionInterface $webform_submission */
$webform_submission = $variables['webform_submission'];
$variable['data'] = $webform_submission->getData();
}
When I use the three options to render the field value within Webform's internal Twig template handler, they work fine, but when I use them in my custom Twig file, they are blank.
Help is appreciated.
Thanks