I want to add TextArea in Admin Edit category Page.

How to do this.


Two steps to create category attribute,

  1. Add a InstallData.php in the below path


then add the below code to it

namespace Vendor\ModuleName\Setup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface;
class InstallData implements InstallDataInterface
 protected $eav_setup;
 protected $connection;
 public function __construct(EavSetupFactory $eavSetupFactory,
    \Magento\Framework\App\ResourceConnection $connection,
    \Magento\Eav\Model\Config $eavConfig
 ) {
     $this->eav_setup_factory = $eavSetupFactory;
     $this->connection = $connection->getConnection();
     $this->eav_config = $eavConfig;
 public function install(
    ModuleDataSetupInterface $setup,
    ModuleContextInterface $context
 ) {

    //create Category Attributes

 protected function createCategoryAttributes($setup)
    $eav_setup = $this->eav_setup_factory->create(['setup' => $setup]);
            'type' => 'text',
            'label' => 'Category Attribute Name',
            'input' => 'textarea',
            'sort_order' => 420,
            'source' => '',
            'global' => ScopedAttributeInterface::SCOPE_STORE,
            'visible' => true,
            'required' => false,
            'user_defined' => false,
            'default' => null,
            'group' => 'Custom Attributes',
            'backend' => ''
  1. Add category_form.xml in the below path to make it visible in admin


then add the below code to it

<?xml version="1.0" ?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
  <fieldset name="custom_attribute">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="label" xsi:type="string">Custom Attributes</item>
            <item name="collapsible" xsi:type="boolean">true</item>
            <item name="sortOrder" xsi:type="number">100</item>
    <field name="attribute_code">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="required" xsi:type="boolean">false</item>
                <item name="validation" xsi:type="array">
                    <item name="required-entry" xsi:type="boolean">false</item>
                <item name="sortOrder" xsi:type="number">40</item>
                <item name="dataType" xsi:type="string">string</item>
                <item name="formElement" xsi:type="string">textarea</item>
                <item name="label" translate="true" xsi:type="string">Category Attribute Name</item>

After done this run the below command

php bin/magento setup:upgrade
php bin/magento cache:flush

NOTE : Make sure your module isn't installed, if installed then delete it from setup module or run the below query in the sql console

DELETE from setup_module where module = 'Vendor_ModuleName';

Hope this helps.

  • How can you show the variable on the front-end? – Sam Jul 14 '20 at 8:23
  • Add a block with class Magento\Catalog\Block\Category\View. Now you can use the function $category = $block->getCurrentCategory(). Next you can get your custom attribute with $category->getCustomAttribute() – Patrick Steenks Dec 11 '20 at 9:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.