Magento2 : How to add custom module configuration in configuration section using system.xml
Here we learn that how to add custom module configuration in Magento2
Basic structure and location of system.xml file
for custom module configuration we need to create system.xml in app/code/Namespace/Modulename/etc/adminhtml
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../Config/etc/system_file.xsd"> </config>
Above written code is common of each system.xml file. This is basic structure of system.xml.
For add new tab in configuration section
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../Config/etc/system_file.xsd"> <system> <!-- for add new tab in Magento2 system configuration section --> <tab id="webkul" translate="label" sortOrder="10"> <label>Webkul</label> </tab> </system> </config>
For add new configuration section with group and fields.
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../Config/etc/system_file.xsd"> <system> <!-- for add new tab in Magento2 system configuration section --> <tab id="webkul" translate="label" sortOrder="10"> <label>Webkul</label> </tab> <!-- for create section --> <section id="sleekaccordian" translate="label" type="text" sortOrder="320" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Sleek Accordian</label> <!-- Assign section to tab --> <tab>webkul</tab> <resource>Webkul_Sleekaccordian::configuration</resource> <!-- create group for fields in section --> <group id="parameters" translate="label" type="text" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Parameters</label> <!-- create text type field --> <field id="slide_speed" translate="label comment" sortOrder="7" type="text" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Slide Speed</label> <comment>e.g 800 .</comment> <validate>validate-number required-entry</validate> </field> </group> </section> </system> </config>
After these your module configuration tab, section, group and field created in store configuration for check goes to store configuration (Store->Configuration) and you get your module configuration section as following
![Selection_024](http://cdnblog.webkul.com/blog/wp-content/uploads/2015/06/Selection_024.png)
Be the first to comment.