---
title: "How to Create Dynamic Generated Field in System Configuration of Magento 2?"
url: "https://magecomp.com/blog/create-dynamic-generated-field-system-configuration-magento-2/"
date: "2019-07-05T17:53:36+00:00"
modified: "2025-02-21T11:14:32+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "How To"
  - "Magento 2"
word_count: 759
reading_time: "4 min read"
summary: "The system configuration is the heart of any extension from where every functionalities and feature can be handled by the store owner. It enables Magento developer to scale and meet customer’s re..."
description: "The system configuration is the heart of any extension from where every functionalities and feature can be handled&hellip;"
keywords: "How To, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "Magento 2:  How to Change Configurable Product Description Dynamically Based on Swatches"
    url: "https://magecomp.com/blog/magento-2-change-configurable-product-description-dynamically-based-on-swatches/"
  - title: "How to Add URL Rewrite for Product Programmatically using Root Script in Magento 2?"
    url: "https://magecomp.com/blog/add-url-rewrite-for-product-programmatically-using-root-script-magento-2/"
  - title: "Magento 2 Store Management Made Easy with Admin Action Login Extension"
    url: "https://magecomp.com/blog/magento-2-admin-action-login-extension-integration-and-guide/"
---

# How to Create Dynamic Generated Field in System Configuration of Magento 2?

_Published: July 5, 2019_  
_Author: Dhiren Vasoya_  

![How to Create Dynamic Generated Field of System Configuration in Magento 2](https://magecomp.com/blog/wp-content/uploads/2019/07/How-to-Create-Dynamic-Generated-Field-of-System-Configuration-in-Magento-2-1024x332.webp)

The system configuration is the heart of any extension from where every functionalities and feature can be handled by the store owner. It enables Magento developer to scale and meet customer’s requirements. Till date, we have written several blogs regarding adding different configuration fields in our MageComp Blog. But many times you came across the requirement of capturing multiple values irrespective of the number of values, at that time we need to use the dynamic field inside backend configuration so the admin can add multiple values using the backend.

[![hyva theme development](https://magecomp.com/blog/wp-content/uploads/2025/02/hyva-theme-development-CTA-2.webp)](https://magecomp.com/services/hyva-theme-development/)

Recently we have written a blog on “[**How to get Dynamic Generated row value of System Configuration in Magento 2**](https://magecomp.com/blog/get-dynamic-generated-row-value-system-configuration-magento-2/)” where you can learn how to fetch values using this dynamic field block, but after that blog some of our readers requested us to write another blog on “How to Create Dynamic Generated Field inside Magento 2 backend configuration”. Because as a developer, many times you need to fetch multiple user inputs at that time making use of Dynamic Generated Field can make your work easy. So simply follow the below steps and create your own dynamic value field in Magento 2 backend configuration.

First, we need to create “**Module.xml**” file inside our custom extension etc folder.
**app\code\Vendor\Extension\etc\Module.xml**

```

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 	       xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
        <module name="Vendor_Extension" setup_version="1.0.0">
    </module>
</config>
```

After that, we need to create one more “**Adminhtml.xml**” in the same folder using below code.
**app\code\Vendor\Extension\etc\Adminhtml.xml**

```

<?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="50">
            <label>Extension</label>
        </tab>
                    <tab>extension</tab>
            <label>Extension</label>
            <resource>Vender_Extension::config_extension</resource>
            <group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>Configuration</label>
                <field id="extension" translate="label" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Extensions</label>
                    <backend_model>VenderExtensionBlockAdminhtmlConfigBackendFileextension</backend_model>
                    <frontend_model>VenderExtensionBlockAdminhtmlFileextension</frontend_model>
                </field>
            </group>
            </system>
</config>
```

[![Magento version upgrade](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Version-Upgrade-CTA-3.webp)](https://magecomp.com/services/magento-upgrade-services/)

Now we need to create one more file “**Fileextension.php**” at this path.
**app\code\Vendor\Extension\Block\Adminhtml\Fileextension.php**

```

<?php
namespace VenderExtensionBlockAdminhtml;

use MagentoConfigBlockSystemConfigFormFieldFieldArrayAbstractFieldArray;

class Fileextension extends AbstractFieldArray
{
	protected function _prepareToRender()
	{
        $this->addColumn(
            'Extensions',
        	[
                'label' => __('Extensions'),
                'size' => '200px'
        	]
    	);
        $this->_addAfter = false;
        $this->_addButtonLabel = __('Add');
	}
}
```

In this last step we need to create **“Fileextension.php”** for creating backend configuration field.

[![Magento 2 Speed & Performance Optimization Services](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Speed-Performance-Optimization-Services-CTA-3.webp)](https://magecomp.com/magento-performance-optimization.html)
**app\code\Vendor\Extension\Block\Adminhtml\Config\Backend\Fileextension.php**

```

<?php
namespace VenderExtensionBlockAdminhtmlConfigBackend;

use MagentoFrameworkAppCacheTypeListInterface;
use MagentoFrameworkAppConfigScopeConfigInterface;
use MagentoFrameworkAppConfigValue as ConfigValue;
use MagentoFrameworkDataCollectionAbstractDb;
use MagentoFrameworkModelContext;
use MagentoFrameworkModelResourceModelAbstractResource;
use MagentoFrameworkRegistry;
use MagentoFrameworkSerializeSerializerInterface;
class Fileextension extends ConfigValue
{
	protected $serializer;
	public function __construct(
        SerializerInterface $serializer,
    	Context $context,
    	Registry $registry,
        ScopeConfigInterface $config,
        TypeListInterface $cacheTypeList,
        AbstractResource $resource = null,
        AbstractDb $resourceCollection = null,
    	array $data = []
	) {
        $this->serializer = $serializer;
        parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
	}
	public function beforeSave()
	{
    	$value = $this->getValue();
        unset($value['__empty']);
        $encodedValue = $this->serializer->serialize($value);
        $this->setValue($encodedValue);
	}
	protected function _afterLoad()
	{
    	$value = $this->getValue();
        if($value) {
            $decodedValue = $this->serializer->unserialize($value);
            $this->setValue($decodedValue);
    	}
	}
}
```

Tadaa! You have successfully created a dynamic field in backend configuration now you are free to manipulate this code according to your development needs.

If you found this blog helpful, don’t forget to share it with your colleagues and Magento Friends.

And, Let us know if you are facing an issue while implementing this code.

Happy Coding!


---

_View the original post at: [https://magecomp.com/blog/create-dynamic-generated-field-system-configuration-magento-2/](https://magecomp.com/blog/create-dynamic-generated-field-system-configuration-magento-2/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-08-20 12:58:56 UTC_  
