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...

  • Have you created demo.phtml ? – zed Blackbeard Mar 19 '18 at 14:54
  • I can't call file knockout js, please help me ! – AVC Aug 29 '19 at 9:44
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."; ?>

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.