Hi
I added a twig template for a specific form's submission to send an email with the results to a specific email address.
I had formatted the results into a set of divs etc to make the results easier to read.
Issue now is that the template been used is the one specified in the email handler.
The filename of the twig template is: webform-email-message-html--customized-email-to-admins.html.twig where "customized-email-to-admins" is the id specified in the handler details.
IS therre something else specific I am supposed to do to ensure the file is used instead of the handler Custom body? Like a HOOK with template suggestion possibly ?
Thanks
John
Comment | File | Size | Author |
---|---|---|---|
#7 | Screen Shot 2018-02-27 at 11.21.41 AM.png | 103.92 KB | jrockowitz |
Comments
Comment #2
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedThe template and suggestions are hard to see because the email template is only rendered when an email is sent via \Drupal\webform\Plugin\WebformHandler\EmailWebformHandler::sendMessage
Below are the template suggestions for the contact form's notification email.
Comment #3
johncogan CreditAttribution: johncogan commentedThanks. I am a little lost on what the 'WEBFORM_HANDLER_PLUGIN_ID' is exactly? I am assuming its going to simply be the same as your contact form example, i.e. 'email'
My webform id = enquire
handler id (as listed on /admin/structure/webform/manage/enquire/handlers) = customized_email_to_admins
Regards and thanks
John
Comment #4
johncogan CreditAttribution: johncogan commentedI have tried all combinations without success:
webform_email_message_html__enquire__email__customized_email_to_admins.html.twig
webform_email_message_html__enquire__email.html.twig
webform_email_message_html__enquire.html.twig
Is there a hook that I can use to 'force' it to use a specific twig file ?
Comment #5
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedI think you just need to replace the underscores with dashes in your *.twig.html files.
@see https://www.drupal.org/docs/8/theming/twig/working-with-twig-templates
Comment #6
johncogan CreditAttribution: johncogan commentedHi jrockowitz.
Many thanks for that. My template is coming through with my markup now but the issue I am having is grabbing the individual submitted values. I originally tried a direct translation of the token and then other iterations.
What I tried was:
The first name element is a plain text field, I haven't even tried grabbing values from List items yet like Checkboxes and select lists.
But none of them work and I cannot find a working example anywhere that hints at grabbing individual element values.
Thanks
John
Comment #7
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedThe email templates variables are very basic. You need to define a template preprocessor to add the submission data to the $variables array.
The below code snippet would allow you to access submission data as
{{ data.email }}
The
webform-email-message-html.html.twig
template is really for just adding a custom header and footer to any sent email. You might want to consider using the Email handler's custom Twig support.Comment #8
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commented@see https://drupal.stackexchange.com/questions/256703/webform-module-transla...
Comment #9
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedComment #10
glennnz CreditAttribution: glennnz commentedI'm struggling with this too; trying to override the default 'webform submitted' email with a twig template. I've selected Twig as the email format and have added just, "This is broken..." to that field.
If my webform name is 'custom_webform' and I've added an email handler to that webform called 'custom_handler', exactly what should my twig file be called?
And, do I need to define this in a hook_theme()? I don't think so.
I'm getting lots of emails telling me that it's broken....
Thanks,
Glenn
Comment #11
glennnz CreditAttribution: glennnz commented@jrockowitz
Re your comment #7, how could I make those submission data items available for use in a node that wanted to display some webform data?
Thanks.
--UPDATE--
I ended up just pushing the webform data into fields on my content type so they become available to the twig file.
Comment #12
glennnz CreditAttribution: glennnz commentedSolved for me.
Selected Twig template as the email handler body format, and named my twig file as webform-email-message-html--WEBFORM-ID.html.twig.
Comment #13
glennnz CreditAttribution: glennnz commented@jrockowitz
I have the twig template working but can't get the webform submission data to show in the email.
I've used your code from comment #7, but can't get the data to display in the email; {{ data }} or {{data.field_name }} both show as empty in the rendered email.
Thanks.
Comment #14
cilefen CreditAttribution: cilefen commented