How to add product tab using xml in admin? I want to show that tab particular product type.
How can i add this product tab using my custom module in magento 2?
you can add this in [Namespace]/[Module]/view/adminhtml/layout/catalog_product_new.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="product_tabs">
<block class="[Namespace]\[module]\Block\Name\Here" name="block.name.here" />
<action method="addTab">
<argument name="name" xsi:type="string">block_name_here</argument>
<argument name="block" xsi:type="string">block.name.here</argument>
</action>
</referenceBlock>
</body>
</page>
then create the block [Namespace]\[module]\Block\Name\Here
that implements Magento\Backend\Block\Widget\Tab\TabInterface
.
Note:This Solution is working Only Magento 2.0x not in 2.1x
data-form-part="product_form"
and i get value of my custom fields
Add xml file to Companyname/Modulename/view/frontend/layout/catalog_product_view.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="product.info.details">
<block class="Companyname\Modulename\Block\yourblockname" name="mycustom.tab" as="mycustom" template="Companyname_Modulename::mytab.phtml" group="detailed_info">
<arguments>
<argument name="title" translate="true" xsi:type="string">My Custom Tab Name</argument>
</arguments>
</block>
</referenceBlock>
</body>
</page>
Add you template file to Companyname/Modulename/view/frontend/templates/mytab.phtml
Hope it will helpful to you.
This Answer is for Magento 2.1.0
In catalog_product_new.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>
<referenceContainer name="product_form">
<block name="class_session" class="[Namespace]\[module]\Block\Adminhtml\Catalog\Product\Edit\Tab\Tabname">
<arguments>
<argument name="config" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Write Name</item>
<item name="collapsible" xsi:type="boolean">true</item>
<item name="opened" xsi:type="boolean">false</item>
<item name="sortOrder" xsi:type="string">33</item>
<item name="canShow" xsi:type="boolean">true</item>
<item name="componentType" xsi:type="string">fieldset</item>
</argument>
</arguments>
</block>
</referenceContainer>
</body>
</page>