5

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 ?

7

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

  • Do we need to create new Module? For Contact Us in Magento 2 we have type text want to change html – Ankit Shah Jan 4 '17 at 3:33
  • @AnkitShah yes you need to create a new module to declare a new custom email template – Raphael at Digital Pianism Jan 4 '17 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 '17 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 '17 at 3:04
  • 1
    @ManthanDave that's a whole other question I suggest you create a new post for it – Raphael at Digital Pianism Apr 11 '17 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.