I am trying to inject my custom product tab in storefront on product view page, but it's not displaying. For this I am written below code.
registration.php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Test_ProductTabs',
__DIR__
);
Test/ProductTabs/Block/CustomTab.php
<?php
namespace Test\ProductTabs\Block;
use Magento\Catalog\Model\Product;
class CustomTab extends \Magento\Framework\View\Element\Template{
/**
* @var Product
*/
protected $_product = null;
/**
* Core registry
*
* @var \Magento\Framework\Registry
*/
protected $_coreRegistry = null;
/**
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \Magento\Framework\Registry $registry
* @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Framework\Registry $registry,
array $data = []
) {
$this->_coreRegistry = $registry;
parent::__construct($context, $data);
}
/**
* @return Product
*/
public function getProduct()
{
if (!$this->_product) {
$this->_product = $this->_coreRegistry->registry('product');
}
return $this->_product;
}
}
Test/ProductTabs/etc/module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Test_ProductTabs" setup_version="1.0.0">
<sequence>
<module name="Magento_Catalog"/>
</sequence>
</module>
</config>
Test/ProductTabs/view/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="Test\ProductTabs\Block\CustomTab" name="mycustom.tab" as="mycustom" template="Test_ProductTabs::kit.phtml" group="detailed_info">
<arguments>
<argument name="title" translate="true" xsi:type="string">Kit Components</argument>
</arguments>
</block>
</referenceBlock>
</body>
</page>
Test/ProductTabs/view/templates/kit.phtml
<h1>Kit Components</h1>
above code is not working for me. Any help on this?