Add theme suggestion for the email-wrap.html.twig template

Created on 5 April 2023, over 1 year ago
Updated 28 April 2023, over 1 year ago

Problem/Motivation

Theme suggestion is not available for the email-wrap template.

Proposed resolution

Add theme suggestion for email-wrap.html.twig

📌 Task
Status

Fixed

Version

1.2

Component

Code

Created by

🇨🇦Canada simgui8 Canada

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Issue created by @simgui8
  • @simgui8 opened merge request.
  • Status changed to Needs review over 1 year ago
  • 🇬🇧United Kingdom adamps

    Thanks for the suggestion.

    Please can you explain how you would like to use this? I imagined that the email template would be used for markup specific to type, and the email wrap would be similar for all types. email-wrap.html.twig has variables for type and sub_type does that help?

  • 🇨🇦Canada simgui8 Canada

    Yes I needed other markups around the body for different types.

    I had those 2 templates to migrates from swiftmailer:
    swiftmailer--commerce--order-receipt.html.twig
    swiftmailer--user--password-reset.html.twig

    I could use email-wrap.html.twig to override all types,
    but couldn't use
    email-wrap--commerce--receipt-resend.html.twig or
    email-wrap--user--password-reset.html.twig

  • 🇬🇧United Kingdom adamps

    Thanks for the reply.

    Could you instead put swiftmailer--user--password-reset.html.twig into email--user--password-reset.html.twig or use the GUI at /admin/config/system/mailer/policy/user.password_reset?

  • 🇨🇦Canada simgui8 Canada

    Well, as for the user--password-reset.html.twig, it's not important.
    Just happened to have a few trivial mods I wanted to keep migrating to Symfony mailer.

    But I know I will for sure want to override email-wrap.html.twig per type in a lot of projects (like commerce projects).

    That leaves me with two options :

    1. adding a theme suggestion for email-wrap.html.twig in each project
    2. adding this MR via a patch

    The patch feels more straightforward and easier to maintain.

  • 🇬🇧United Kingdom adamps

    Sure I understand what you wish to do, thanks for explaining.

    When I wrote the template code, I had expected that email-wrap.html.twig would be used for general markup that was the same for all emails. Then email.html.twig (or mailer policy GUI) would be used for markup that was different for each type. Is there is a reason why you can't do it that way?

  • 🇨🇦Canada simgui8 Canada

    I understand thanks.

    Some of the things I may want per type:

    • having styles in a head section
    • doctypes
    • inline styles on the body

    Plus verifying each different email once. Changing email-wrap.html.twig may impact other templates.
    When new "rich" email templates are added over time, they may have different wrappers.

  • 🇬🇧United Kingdom adamps

    Thanks however I already understand that you want to change things per type.

    As I already mentioned, there are three existing ways of changing things per type:

    1. Suggestions for email.html.twig
    2. Mailer Policy in the GUI
    3. Conditional code within email-wrap.html.twig using type variable

    Please can you explain why none of those work for you and you feel we need a 4th way?

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    5 pass
  • Status changed to Fixed over 1 year ago
  • 🇬🇧United Kingdom adamps

    OK thanks for the patch and explanation. Done with doc updates at https://www.drupal.org/docs/contributed-modules/drupal-symfony-mailer/ge... .

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024