6

I have created system.xml file in my module but it is show me blank

enter image description here

Path:-app/code/Amitshree/Customer/etc/adminhtml/system.xml

Code:-

<?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>
        <tab id="bliss" translate="label" sortOrder="10">
            <label>bliss</label>
        </tab>
        <section id="cust" translate="label" sortOrder="130" showInDefault="1" showInWebsite="1" showInStore="1">
            <class>separator-top</class>
            <label>Customer</label>
            <tab>bliss</tab>
            <resource>Amitshree_Customer::customer_config</resource>
            <group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
                <label>General Configuration</label>
                <field id="your_email_template_field_id" translate="label comment" type="select" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Label Of Your Field</label>
                    <source_model>Magento\Config\Model\Config\Source\Email\Template</source_model>
                    <!-- This model return all transactional email template list of magento -->
                </field>
            </group>
        </section>
    </system>
</config>

Error:-enter image description here

app/code/Amitshree/Customer/etc/email_templates.xml

<?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="your_email_template_id" label="Label Of Your Template File" file="your_email_template.html" type="html" module="Amitshree_Customer" area="adminhtml"/>
</config>
<!-- here you define your email template and its template location path-->

app/code/Amitshree/Customer/etc/config.xml

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../Store/etc/config.xsd">
    <default>
    </default>
</config>
  • It's showing due to this line <source_model>Magento\Config\Model\Config\Source\Email\Template</source_model> – Navin Bhudiya Jan 19 '18 at 7:02
  • Please follow this answare for same magento.stackexchange.com/questions/183678/… – Navin Bhudiya Jan 19 '18 at 7:05
  • which version are you follow mage 2.2.2? – Rakesh Jesadiya Jan 23 '18 at 10:13
  • I tried in Magento 2.1.8 as well in 2.2.2 but not working. If I try any source model except template than it is working perfectly @RakeshJesadiya – Jaimin Jan 23 '18 at 10:16
  • @RakeshJesadiya When i try in magento 2.1.8 it shows blank but when i try in magento 2.2.2 its give an error which i attached in screenshot for now i want to do in magento 2.2.2 – Jaimin Jan 23 '18 at 10:18
5
+50

Kindly set your email_templates.xml file under etc folder with below contents,

<?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="cust_general_your_email_template_field_id" label="Label Of Your Template File" file="your_email_template.html" type="html" module="Amitshree_Customer" area="adminhtml"/>
</config>

You need to pass your template with id equals to cust_general_your_email_template_field_id

Remove var/generation folder or generated folder from root.

  • how did you know that we have to use cust_general_your_email_template_field_id – Jaimin Jan 23 '18 at 11:11
  • i have faced same error in past and i have resolved it using set template id as error id. – Rakesh Jesadiya Jan 23 '18 at 11:12
  • ok means i have to refer sections and group ids of system.xml right? – Jaimin Jan 23 '18 at 11:12
  • no you just set inside email_templates.xml file. Just try using delete var and generated folder – Rakesh Jesadiya Jan 23 '18 at 11:13
  • yes it is working. :) – Jaimin Jan 23 '18 at 11:14
0

Replace your source model with this

<source_model>Amitshree\Customer\Model\Config\Source\Email\Template</source_model>

and create Template.php at

app/code/Amitshree/Customer/Model/Config/Source/Email/Template.php

<?php

namespace Amitshree\Customer\Model\Config\Source\Email;

class Template extends \Magento\Framework\DataObject implements \Magento\Framework\Option\ArrayInterface
{

    private $_coreRegistry;

    private $_emailConfig;

    protected $_templatesFactory;


    public function __construct(
        \Magento\Framework\Registry $coreRegistry,
        \Magento\Email\Model\ResourceModel\Template\CollectionFactory $templatesFactory,
        \Magento\Email\Model\Template\Config $emailConfig,
        array $data = []
    ) {
        parent::__construct($data);
        $this->_coreRegistry = $coreRegistry;
        $this->_templatesFactory = $templatesFactory;
        $this->_emailConfig = $emailConfig;
    }

    /**
     * Generate list of email templates
     *
     * @return array
     */
    public function toOptionArray()
    {
        /** @var $collection \Magento\Email\Model\ResourceModel\Template\Collection */
        if (!($collection = $this->_coreRegistry->registry('config_system_email_template'))) {
            $collection = $this->_templatesFactory->create();
            $collection->load();
            $this->_coreRegistry->register('config_system_email_template', $collection);
        }
        return $options;
    }
}
0

Try this code:-

        <section id="cust" translate="label" type="text" sortOrder="130" showInDefault="1" showInWebsite="1" showInStore="1">            
            <label>Customer</label>
            <tab>bliss</tab>
            <resource>Amitshree_Customer::customer_config</resource>
            <group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
                <label>General Configuration</label>
                <field id="your_email_template_field_id" translate="label comment" type="select" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Label Of Your Field</label>
                    <source_model>Magento\Config\Model\Config\Source\Email\Template</source_model>
                    <!-- This model return all transactional email template list of magento -->
                </field>
            </group>
        </section>

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.