3

How to get Email Templates in stores configuration in custom Tab. Please find the below link http://prntscr.com/fvi0og

can anyone help me on this. thanks

2

You have to give like system.xml:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
    <system>
        <section id="paytrade" translate="label" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
            <group id="general" translate="label" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
                <field id="paytrade_commission_template" translate="label" type="select" sortOrder="3" showInDefault="1" showInStore="1" showInWebsite="1">
                    <label>Test Tab Email Template</label>
                    <comment>Test tab email sent to xyz.</comment>        
                    <source_model>Magento\Config\Model\Config\Source\Email\Template</source_model>
                </field>
            </group>
        </section>
    </system>
</config>

showInStore="1" is for show in storeview.

and another file at /app/code/vendor/modulename/etc/email_templates.xml have to like:

<?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../Email/etc/email_templates.xsd">
    <template id="paytrade_general_paytrade_commission_template" label="Test Tab Email Template" file="test_tab_template_email.html" type="html" module="Ewall_Paytrade" area="frontend"/>
</config>

and Create email template file at like: /Ewall/Paytrade/view/frontend/email/test_tab_template_email.html

| improve this answer | |
  • thanks..i think there is no full code in the comment – Raghu Jul 14 '17 at 5:16
  • I have updated answer – Emipro Technologies Pvt. Ltd. Jul 14 '17 at 5:19
  • ok thanks let me try this and get back to you within 2min – Raghu Jul 14 '17 at 5:20
  • this is showing empty page when code applied – Raghu Jul 14 '17 at 5:23
  • have you also created file "email_templates.xml" at /app/code/vendor/modulename/etc/email_templates.xml ? – Emipro Technologies Pvt. Ltd. Jul 14 '17 at 5:26
1

To begin with create a email_templates.xml file in app/code/VendorName/CustomModule/etc folder with the following content.

<?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="section_id_group_id_field_id" label="Customer Credit Report" file="email_report.html" type="html" module="VendorName_CustomModule" area="frontend"/>

</config>

Where template id is the email template identifier and a file with name email_report has got its message in html format. The template identifier will be provided based on the section_id_group_id_field_id which we declare it in the system.xml which will be explained in the following sections.

Create a template file in the path app/code/VendorName/CustomModule/view/frontend/email/email_report.html and the content for email can be added by declaring the template variables from the action file. For instance here the Customer details has been set as a content for email.

    {{template config_path="design/email/header_template"}}
<!--@subject Custom Email@-->
<!--@vars {
"var data.email":"Sender Email",
"var data.name":"Sender Name"
} @-->
<ul>
<li>
<strong>Customer Details:</strong>
<div>
<p>{{trans “Name:  %name" name=$templateParams.name}}</p>
<p>{{trans “Email:  %Email" Email=$templateParams.email}}</p>
</div>
</li></ul>
{{template config_path="design/email/footer_template"}}

The Created email template can be configured from the admin by creating the system.xml file. Add a file system.xml with the following code in the path app/code/VendorName/CustomModule/etc/adminhtml/. This will hold a default value for email template which will be defined in config.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<section id="section_id" translate="label" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<group id="group_id" translate="label" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<field id="field_id" translate="label comment" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Label to your field</label>
<source_model>Magento\Config\Model\Config\Source\Email\Template</source_model>
</field>
</group>
</section>
</system>
</config>

Create a config.xml file in the path app/code/VendoName/CustomModule/etc/ for setting the default template value in the admin custom field that has been created using system.xml.

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<default>
<section_id>
<group_id>
<field_id>section_id_group_id_field_id</field_id>
</section_id>
</group_id>
</default>
</config>
| improve this answer | |
  • thanks.. tried this one but iam getting empty page – Raghu Jul 14 '17 at 5:29
  • in the field_id i have given "paytrade_commission_template" and in the config.xml i kept like this <paytrade_commission_template>custom_email_name</paytrade_commission_template> – Raghu Jul 14 '17 at 5:32
  • prntscr.com/fvi86y – Raghu Jul 14 '17 at 5:33
  • magento.stackexchange.com/questions/183281/… From this $customEmailPath = 'sales_email/order/template'; I cannot save my custom template for order email so i thought to get from custom path so that it will be like this: $customEmailPath = 'paytrade_commission/email/template'; – Raghu Jul 14 '17 at 5:42
  • is your section id is paytrade_commission, group id is email and field id is template? – Haritha Jul 14 '17 at 5:46

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.