Magento 2: how to declare a custom email template for your module
-
14-04-2021 - |
سؤال
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 ?
المحلول
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
لا تنتمي إلى magento.stackexchange