How To

Magento 2: How to Divide System Configuration Groups in Multiple .xml Files?

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.

Steps to Divide System Configuration Groups in Multiple .xml Files in Magento 2:

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.

Conclusion:

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!

Click to rate this post!
[Total: 5 Average: 5]
Dhiren Vasoya

Dhiren Vasoya is a Director and Co-founder at MageComp, Passionate ?️ Certified Magento Developer?‍?. He has more than 9 years of experience in Magento Development and completed 850+ projects to solve the most important E-commerce challenges. He is fond❤️ of coding and if he is not busy developing then you can find him at the cricket ground, hitting boundaries.?

Recent Posts

Generating Thumbnails with Spatie Media Library in Laravel 11: A Step-by-Step Guide

Generating image thumbnails is a common requirement in web applications, especially when handling media-heavy content.…

18 hours ago

Enhancing Web Application Security with Laravel’s Built-In Features

In today’s digital landscape, web application security is paramount. As a powerful PHP framework, Laravel…

2 days ago

Magento 2 Extensions Digest October 2024 (New Release & Updates)

October was an exciting month for MageComp! From significant updates across our Magento 2 extension…

2 days ago

Improving Error Handling and Transition Management in Remix with useRouteError and useViewTransitionState

In modern web development, seamless navigation and state management are crucial for delivering a smooth…

1 week ago

Magento Open Source 2.4.8-Beta Release Notes

Magento Open Source 2.4.8 beta version released on October  8, 2024. The latest release of…

2 weeks ago

How to Create Catalog Price Rule in Magento 2 Programmatically?

Hello Magento Friends, Creating catalog price rules programmatically in Magento 2 can be a valuable…

2 weeks ago