Hello Magento Friends,
In this tutorial, I am going to describe Magento 2: How to Divide System Configuration Groups in Multiple .xml Files?
Sometimes developers need to divide system configuration groups in multiple .xml files, so other developers can easily understand where we have created system configuration groups.
Let’s dive into How to Divide System Configuration Groups in Multiple .xml Files in Magento 2.
Contents
Step 1: First, create a “system.xml” file inside the extension at the below-given path.
app\code\Vendor\Extension\etc\adminhtml\
Now add the below 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="extension" translate="label" sortOrder="100" class=""> <label><![CDATA[Custom Tab]]></label> </tab> <section id="customgroup" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Custom Tab</label> <tab>extension</tab> <resource>Vendor_Extension::customgroupconfig</resource> <group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Configuration</label> <field id="enable" translate="label comment" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Enable</label> <source_model>Magento\Config\Model\Config\Source\Enabledisable</source_model> </field> </group> <include path="Vendor_Extension::system/group1.xml"/> <include path="Vendor_Extension::system/group2.xml"/> </section> </system> </config>
Step 2: After that, we need to create a “group1.xml” file at the following path.
app\code\Vendor\Extension\etc\adminhtml\system\
Then add the below code
<?xml version="1.0"?> <include xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_include.xsd"> <group id="custom_1" translate="label" type="text" sortOrder="15" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Custom Configuration</label> <field id="active" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Enabled</label> <source_model>Magento\Config\Model\Config\Source\Yesno</source_model> </field> </group> </include>
Step 3: After that, we need to create a “group2.xml” file at the below path.
app\code\Vendor\Extension\etc\adminhtml\system\
And add the code as follows
<?xml version="1.0"?> <include xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_include.xsd"> <group id="custom_2" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Custom Configuration 1</label> <field id="active" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Enabled</label> <source_model>Magento\Config\Model\Config\Source\Yesno</source_model> </field> </group> </include>
You can see that the system configuration groups are divided in the Magento 2 backend.
Accordingly, you can Divide System Configuration Groups into Multiple .xml Files in Magento 2. Additionally, learn How to Create System.xml Configuration in Magento 2.
If you face any difficulty let me know through the comment box. Share the article with your colleagues and stay updated with our latest Magento 2 tutorials.
Happy Coding!
Generating image thumbnails is a common requirement in web applications, especially when handling media-heavy content.…
In today’s digital landscape, web application security is paramount. As a powerful PHP framework, Laravel…
October was an exciting month for MageComp! From significant updates across our Magento 2 extension…
In modern web development, seamless navigation and state management are crucial for delivering a smooth…
Magento Open Source 2.4.8 beta version released on October 8, 2024. The latest release of…
Hello Magento Friends, Creating catalog price rules programmatically in Magento 2 can be a valuable…