3

Just as the title indicates, I'm looking for a way to customize the email template of the "click here to activate your account" email that is sent to users when they register. I would also like to know if its possible and how to do this with other system email templates, such as the reset password link email.

Edit: I see you can edit the plain text emails at Settings > Email > Messages however I would like to be able to define a twig template to handle creating HTML versions of these.

7

Actually Brad, I was able to figure out a way to do this with some help from @carlcs in the slack channel.

I defined an "HTML Template" in the main email settings screen, then in that template I extend a basic HTML email wrapper, then inside my content block I did this:

{% if emailKey == 'account_activation' %}
    {% include 'mail/activation' %}
{% endif %}
{% if emailKey == 'forgot_password' %}
    {% include 'mail/forgot-password' %}
{% endif %}
{% if emailKey == 'test_email' %}
    {% include 'mail/test-email' %}
{% endif %}
{% if emailKey == 'verify_new_email' %}
    {% include 'mail/verify-new-email' %}
{% endif %}

Then I just created HTML versions of each email within the context of my wrapper.

It works perfectly!

| improve this answer | |
  • 1
    Ahh... clever!! – Brad Bell Oct 19 '17 at 16:43
  • Hi Rick, could you explain a little bit more what you did? Where is the main email settings screen (Utilities / System messages ?) Thanks. – migswd Feb 7 at 10:57
  • 1
    @migswd Sorry for the delay. I believe this post was originally made based on Craft2, not Craft3. I don't think there is a spot for that setting in craft3 anymore. – Rick Kukiela Mar 9 at 18:02
3

With @sublymerick's answer as inspiration I define a default html template, _emails/index.twig, passing in the message content that is defined in Craft admin to an html wrapper rather than create separate templates for each.

{% if emailKey is defined and emailKey in [
    'account_activation', 
    'forgot_password', 
    'test_email', 
    'verify_new_email'] 
%}    
    {% include '_emails/templates/basic' with {
        body: body | raw,
    } only %}
{% endif %}
| improve this answer | |
  • Hi Seth. Could you explain a little bit more what you did? What do you have in _emails/templates/basic ? Thanks. – migswd Feb 7 at 11:04
  • _emails/templates/basic is the markup (tables, urgh!) for the email body. So rather than maintaining seperate templates for each message I'd code up the email with everything required (logo, header, footer links, etc) then just pass the message body into that. – Seth Warburton Feb 7 at 15:39
  • Great thank you ! :) – migswd Feb 8 at 9:12
1

I see you can edit the plain text emails at Settings > Email > Messages however I would like to be able to define a twig template to handle creating HTML versions of these.

Currently not possible natively, but there is a feature request you might want to add a thumbs-up/comment to:

https://github.com/craftcms/cms/issues/1020

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.