Problem/Motivation

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

Proposed resolution

Add theme suggestion for email-wrap.html.twig

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

simgui8 created an issue. See original summary.

simgui8’s picture

Status: Active » Needs review
adamps’s picture

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?

simgui8’s picture

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

adamps’s picture

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?

simgui8’s picture

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.

adamps’s picture

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?

simgui8’s picture

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.

adamps’s picture

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?

simgui8’s picture

No problem, here:

1: same as #9

2: I already have added a Mailer Policy (great feature), however, I couldn't find how it gives me control over the body wrapper from email-wrap.html.twig

3: Sound like an alternative I "could" use but things might get bloated.

The very existence of email-wrap.html.twig template kinda makes me expect type suggestion would exist.

I feel it's simpler and leaner.

  • AdamPS committed cd1054a5 on 1.x authored by simgui8
    Issue #3352469 by simgui8: Add theme suggestion for the email-wrap.html....
adamps’s picture

Status: Needs review » Fixed

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

Status: Fixed » Closed (fixed)

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

anybody’s picture

Running into this, I think the sentence

By default (coming from the pre-installed "Wrap and Convert" Mailer policy set for all emails), the email is wrapped in a second template email-wrap, with suggestions in the same way.

should have its own example.

Am I right that it would be like this?

For example, to set a template for user password reset emails the wrap template would be email-wrap--user--password-reset.html.twig.

?

Then I'd add it, just want to be sure it's correct!

anybody’s picture

Assigned: simgui8 » Unassigned

@adamps could you maybe tell if my assumption is correct or add an example?