How to Create System.xml Configuration In Magento 2
Magento 2 is a feature-rich platform with default functionalities suitable for E-commerce businesses. However, with the evolving nature of shopping online and types of businesses, the default Magento 2 falls short. Fortunately, due to the customization capability of the platform, the store owners can use Magento 2 extensions to implement additional functionalities.
Now, there are many extensions where the store owner or admin has to configure a few settings and for which one needs to create system.xml configuration in Magento 2.
Allow the admin to flexibly configure the module by offering fields at Admin Panel > Stores > Configuration.
Example:
Create system.xml configuration file in Magento 2 with the below code:
Steps to create system.xml configuration in Magento 2:
Create system.xml file at app\code\Vendor\Extension\etc\adminhtml\
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<?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="vendor" translate="label" class="vendor" sortOrder="100"> <label>vendor</label> </tab> <section id="extension" translate="label" type="text" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1"> <class>separator-top</class> <label>Extension</label> <tab>vendor</tab> <resource>Vendor_Extension::config_extension</resource> <group id="general" translate="label" type="text" sortOrder="20" 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>Extension Enable</label> <source_model>Magento\Config\Model\Config\Source\Enabledisable</source_model> </field> </group> </section> </system> </config> |
That’s it.
Any doubts about the topic? Feel free to mention them in the Comments section below. I’d be happy to help.
Please share the solution with fellow Magento developers via social media.
Thank you.
Sanjay Jethva
Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe.
His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.
2 Comments
It is not working, the configuration was not created.
Hello Aman,
The above code is working properly from our end.
What issues you are facing?
Thank You.