I want to add a custom tab on product page, just like (Details, More Information, Reviews) .
What is the approach to implement this task.
Any help will be appreciated.
app/code/Ravindra/HelloWorld/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="Magento\Catalog\Block\Product\View" name="demo.tab" template="Ravindra_HelloWorld::custom_tab.phtml" group="detailed_info" >
<arguments>
<argument translate="true" name="title" xsi:type="string">Cutom Tab</argument>
</arguments>
</block>
</referenceBlock>
</body>
</page>
app/code/Ravindra/HelloWorld/View/frontend/templates/custom_tab.phtml
<?php // Get current product
$product = $block->getProduct();
?>
<h1 style="color: #ff5501"><?php echo $product->getData('demo'); ?></h1>
Add below code to your theme Magento_Catalog >> Layout >> catalog_product_view.xml
<referenceBlock name="product.info.details">
<block class="<vendor>\<module>\Block\Product\View\Attributes" name="custom_product_tab" template="<Vendor>_<ModuleName>::product/tabs/custom.phtml" group="detailed_info">
<arguments>
<argument translate="true" name="title" xsi:type="string">Custom</argument>
</arguments>
</block>
</referenceBlock>
If you want to add static content you can add
Magento\Catalog\Block\Product\View
class in Block instead of custom class
Thanks!