6

In Magento 1, you could declare email templates directly in the config.xml like this:

<template>
    <email>
        <custom_email_template translate="label" module="modulename">
            <label>Custom Email Template</label> 
            <file>vendor/modulename/custom_email_template.html</file>
            <type>html</type>
        </custom_email_template>
    </email>
</template>

Then you only had to create the following file app/locale/<lang_LANG>/template/email/vendor/modulename/custom_email_template.html

How can we achieve that in Magento 2 ?

1 Answer 1

12

In Magento 2, you have to declare your custom email templates under the etc/email_templates.xml in your app/code/Vendor/Module folder.

Based on the question, a working example would be:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Email:etc/email_templates.xsd">
    <template id="custom_email_template" label="Custom Email Template" file="custom_email_template.html" type="html" module="Vendor_Module" area="frontend"/>
</config>

Take note of the area attribute that can be either frontend or adminhtml and that was not declared in M1.

Then you need to create your custom email template under app/code/Vendor/Module/view/<area>/email/custom_email_template.html

9
  • Do we need to create new Module? For Contact Us in Magento 2 we have type text want to change html
    – Jackson
    Jan 4, 2017 at 3:33
  • @AnkitShah yes you need to create a new module to declare a new custom email template Jan 4, 2017 at 11:42
  • @RaphaelatDigitalPianism. This above code at which place will work. Suppose i want this template at catalog_index_index (at product detail page). Then should we need to do?
    – Pinku
    Jan 5, 2017 at 15:47
  • is this enough to be able to use that template in email templates as {{template config_path="custom_email_template"}} ?
    – fassl
    Jan 18, 2017 at 3:04
  • 1
    @ManthanDave that's a whole other question I suggest you create a new post for it Apr 11, 2017 at 7:07

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.