2

I want to create a custom tab in admin category_from page. After create custom tab i want to call a phtml file.

I have successfully created a custom tab in category_form but when i try to call a block it gives me an error showing

a:4:{i:0;s:94:"The requested component ("block") is not found. Before using, you must add the implementation.";i:1;s:7167:"#0 /var/www/practice/vendor/magento/module-ui/Model/Manager.php(207): Magento\Framework\View\Element\UiComponent\Config\Provider\Component\Definition->getComponentData('block')

This what i have done

category_form.xml

    <?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<!--    <body>-->
<!--        <referenceBlock name="category_form">
            <block class="Panacea\Custom\Block\Adminhtml\Category\Tab\Custom" name="demo.tab">
                <arguments>
                    <argument name="config" xsi:type="array">
                        <item name="label" xsi:type="string" translate="true">Custom Design</item>
                        <item name="collapsible" xsi:type="boolean">true</item>
                        <item name="opened" xsi:type="boolean">true</item>
                        <item name="sortOrder" xsi:type="string">2</item>
                        <item name="canShow" xsi:type="boolean">true</item>
                        <item name="componentType" xsi:type="string">fieldset</item>
                    </argument>
                </arguments>
            </block>
        </referenceBlock>-->
        <fieldset name="Custom">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="label" xsi:type="string" translate="true">Custom Design</item>
                <item name="collapsible" xsi:type="boolean">true</item>
                <item name="sortOrder" xsi:type="number">100</item>
            </item>
        </argument>
<!--        <field name="custom_attribute">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="sortOrder" xsi:type="number">1</item>
                    <item name="dataType" xsi:type="string">string</item>
                    <item name="formElement" xsi:type="string">input</item>
                    <item name="label" xsi:type="string" translate="true">Custom Attribute</item>
                </item>
            </argument>-->
        <!--</field>-->
<!--        <block class="Panacea\Custom\Block\Adminhtml\Category\Tab\Custom" name="demo.tab">               
            </block>-->
        <!--<block class="Magento\Framework\View\Element\Template" name="CustomTab" template="Panacea_Custom::demo.phtml"></block>-->
         <block class="Magento\Framework\View\Element\Template" name="customtab" template="Panacea_Custom::demo.phtml">
                <arguments>
                    <argument name="config" xsi:type="array">
                        <item name="label" xsi:type="string" translate="true">Custom</item>
                        <item name="collapsible" xsi:type="boolean">true</item>
                        <item name="opened" xsi:type="boolean">true</item>
                        <item name="sortOrder" xsi:type="string">2</item>
                        <item name="canShow" xsi:type="boolean">true</item>
                        <item name="componentType" xsi:type="string">fieldset</item>
                    </argument>
                </arguments>
            </block>
    </fieldset>
<!--    <referenceBlock name="content">
            <block class="Magento\Framework\View\Element\Template" name="demo.tab">
                <arguments>
                    <argument name="config" xsi:type="array">
                        <item name="label" xsi:type="string" translate="true">Custom</item>
                        <item name="collapsible" xsi:type="boolean">true</item>
                        <item name="opened" xsi:type="boolean">true</item>
                        <item name="sortOrder" xsi:type="string">2</item>
                        <item name="canShow" xsi:type="boolean">true</item>
                        <item name="componentType" xsi:type="string">fieldset</item>
                    </argument>
                </arguments>
            </block>
        </referenceBlock>-->
    <!--</body>-->
</page>

and in the comment sessions i have tried to call my block, which i get error all the time. Need some help

Thanks

2

Your category_form.xml Vendor/Module/view/adminhtml/ui_component/category_form.xml should be

<?xml version="1.0" encoding="UTF-8"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <fieldset name="custom_fieldset">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="label" xsi:type="string" translate="true">Custom Tab</item>
                <item name="collapsible" xsi:type="boolean">true</item>
                <item name="sortOrder" xsi:type="number">140</item>
            </item>
        </argument>
        <container name="custom_fieldset_container" >
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="sortOrder" xsi:type="number">200</item>
                </item>
            </argument>
            <htmlContent name="html_content">
                <argument name="block" xsi:type="object">Vendor\Module\Block\Adminhtml\Category\Custom</argument>
            </htmlContent>
        </container>
    </fieldset>
</form>

Now create Vendor/Module/Block/Adminhtml/Category/Custom.php

namespace Vendor\Module\Block\Adminhtml\Category;

class Custom extends \Magento\Backend\Block\Template
{
    /**
     * Block template
     *
     * @var string
     */
    protected $_template = 'custom.phtml';
}

And create template Vendor/Module/view/adminhtml/templates/custom.phtml

<h1>Custom Tab Content</h1>

Clear cache.

  • Got what i wannted – Mandar Parbate May 5 '17 at 7:06
  • protected $_template = 'custom.phtml'; This is ignore by coding standard tool. – Dhaduk Mitesh Sep 27 '18 at 9:42

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.