1

How to add tab in product edit page in magento2?

I refering some tutorial ...but its not woking for me...

https://webkul.com/blog/add-tab-product-page-magento-admin/

If anyone knows ,Explain me...

2
  • Have you created demo.phtml ? Commented Mar 19, 2018 at 14:54
  • I can't call file knockout js, please help me !
    – AVC
    Commented Aug 29, 2019 at 9:44

1 Answer 1

2

You can add custom tab using UI component

  1. app/code/Namespace/Modulename/view/adminhtml/ui_component/product_form.xml
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <fieldset name="demotab">
       <argument name="data" xsi:type="array">
           <item name="config" xsi:type="array">
               <item name="label" xsi:type="string" translate="true">Demo Tab</item>
               <item name="collapsible" xsi:type="boolean">true</item>
               <item name="sortOrder" xsi:type="number">100</item>
           </item>
       </argument>
       <container name="fieldname_container" >
           <argument name="data" xsi:type="array">
               <item name="config" xsi:type="array">
                   <item name="sortOrder" xsi:type="number">160</item>
               </item>
           </argument>
           <htmlContent name="html_content_demo">
               <argument name="block" xsi:type="object">Namespace\Modulename\Block\Adminhtml\Catalog\Product\Edit\Tab\Demo</argument>
           </htmlContent>
       </container>
   </fieldset>
</form>
  1. app/code/Namespace/Modulename/Block/Adminhtml/Catalog/Product/Edit/Tab/Demo.php
<?php
namespace Namespace\Modulename\Block\Adminhtml\Catalog\Product\Edit\Tab;

use Magento\Backend\Block\Template\Context;
use Magento\Framework\Registry;

class Demo extends \Magento\Framework\View\Element\Template
{
    /**
     * @var string
     */
    protected $_template = 'product/edit/demo.phtml';

    /**
     * Core registry
     *
     * @var Registry
     */
    protected $_coreRegistry = null;

    public function __construct(
        Context $context,
        Registry $registry,
        array $data = []
    )
    {
        $this->_coreRegistry = $registry;
        parent::__construct($context, $data);
    }

    /**
     * Retrieve product
     *
     * @return \Magento\Catalog\Model\Product
     */
    public function getProduct()
    {
        return $this->_coreRegistry->registry('current_product');
    }

}
  1. app/code/Namespace/Modulename/view/adminhtml/templates/product/edit/demo.phtml
<?php echo "This is demo tab content."; ?>
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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