Is it possible to add custom tab in product page remains in custom module(with out changing template of theme). if it's not possible help me in extending template of theme to adding custom tab in product page.
Magento 2 – How to Add Custom Tab in Product Page
custommagento2moduleproduct
Related Solutions
Please only ask one question at once. Anyway, here you go:
The following content for the
local.xml
works. It will add a new tab on the product page. If it does not work, your layout XML file is probably not loaded correctly.<?xml version="1.0"?> <layout version="0.1.0"> <catalog_product_view> <reference name="product.info"> <block type="catalog/product_view_attributes" name="features_product_tab" as="features_tab" template="catalog/product/view/features.phtml"> <action method="addToParentGroup"><group>detailed_info</group></action> <action method="setTitle" translate="value"><value>Features</value></action> </block> </reference> </catalog_product_view> </layout>
This is not possible in a nice way. But you could write something unique into the static block to mark it empty and then change the way Magento renders the tabs in order to hide "empty" tabs. Therefore, write e.g.
EMPTY
into the static block you do not want to be rendered. Magento will automatically add a paragraph tag around it, so it becomes<p>EMPTY</p>
. Then, in yourcatalog/product/view.phtml
change the tab rendering like that:<div class="product-collateral toggle-content tabs"> <?php if ($detailedInfoGroup = $this->getChildGroup('detailed_info', 'getChildHtml')):?> <dl id="collateral-tabs" class="collateral-tabs"> <?php foreach ($detailedInfoGroup as $alias => $html):?> <?php if ($html != '<p>EMPTY</p>'): ?> <dt class="tab"><span><?php echo $this->escapeHtml($this->getChildData($alias, 'title')) ?></span></dt> <dd class="tab-container"> <div class="tab-content"><?php echo $html ?></div> </dd> <?php endif; ?> <?php endforeach;?> </dl> <?php endif; ?> </div>
You need to add this in the layout xml file from one of your modules (or local.xml
of your theme).
<catalog_product_view>
<reference name="product_info">
<block type="your_block/alias_here" name="some_name_here" as="some_alias_here" template="path/to/template.phtml">
<action method="addToParentGroup"><group>detailed_info</group></action>
<action method="setTitle" translate="value"><value>Tab Title Here</value></action>
</block>
</reference>
</catalog_product_view>
Then create your block and the template with the content you need.
Best Answer
Yes its possible through your module instead of write code in theme file.
In Magento 2 to apply the new tab in product detail page is very easy task. Use below steps and check it out. It will display the tab in your theme.
catalog_product_view.xml
in the app/design/frontend/{vender name}/{theme name}/Magento_Catalog/layoutIn the file write the below code:
delivery_info.phtml
in the path app/design/frontend/{vender name}/{theme name}/Magento_Catalog/templates/product/view.In the file you can write any content or you can call the static block like this
delivery_info
block we have to create in admin sideContent/Block
.run
php bin/magento cache:clean
Now check in the Detail page.