- 🇩🇪Germany Anybody Porta Westfalica
I agree this would make sense, to allow more reliable and flexible definition of the mail templates, similar to commerce-order-receipt.html.twig.
I think it would even be the better alternative to ✨ Add CKEditor support to the email body textarea Needs review , at least for developers / themers, propably not for non-coders.So we could think about:
a) Having this as contrib or submodule
b) Having this configurable
c) Have an override order, so that the textarea / WYSIWYG can be used, but is rendered by a twig file, which gets all the variables as twig variables and is thereby able to fully replace the need to use the textarea / WYSIWYG.I very much like C as it could be integrated and would use progressive enhancement and standard Drupal logics.
@Honza Pobořil to push this forward, you could write a MR implementing this.
- 🇹🇷Turkey rgnyldz
It would be nice to have this in-module but an alternative would be to use symfony mailer where we can already use templates for certain policies. And this module already suggests to use symfony mailer.
- Status changed to Needs review
11 months ago 1:53pm 29 December 2023 - 🇨🇭Switzerland tcrawford
As previously mentioned by RgnYldz if using the symfony mailer it is possible already to use twig templates without the patch. Due to this, I am not sure this is really needed. The existing inline template approach also has advantages in some use cases. I can imagine though that if this patch is added it would make sense to consider making it configurable.
As an example of using symfony mailer with a specific hook_preprocess_HOOK() implementation for a specific mail type.
<?php // mytheme.theme /** * Implements hook_preprocess(). */ function mytheme_preprocess_email__commerce__commerce_email_publication_fulfillment_mail(&$variables): void { $email = $variables['email']; if (!$email instanceof Email) { return; } $entity = $email->getEntity(); // Currently commerce_email does not set the entity on the email. We can get // this from the legacy_message param though. if ($entity === NULL) { $legacy_message = $email->getParam('legacy_message'); // The context that is passed to the inline template. $context = $legacy_message['params']['body']['#context'] ?? NULL; if ($context) { $entity = $context[array_key_first($context)]; } } if ($entity) { // Mail specific pre-processing. _mytheme_preprocess_publication_fulfillment_mail($variables, $entity); } } ?>
You can then create a twig template for the specific mail, such as in my case: email--commerce--commerce-email-publication-fulfillment-mail.html.twig
- 🇺🇦Ukraine marchuk.vitaliy Rivne, UA
vmarchuk → made their first commit to this issue’s fork.
- Merge request !13Issue #3156158: Support rendering an email using a Twig template. → (Open) created by Unnamed author
- 🇺🇦Ukraine marchuk.vitaliy Rivne, UA
Tested MR together with the issue ✨ Add CKEditor support to the email body textarea Needs review and it works great.