Version – 1.9
Theme : rwd
I followed this to add custom product tabs in product detail page. To add a new block I added below code in local.xml
, but somehow it only works if I add it in catalog.xml
<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>
Adding the <block>
in catalog.xml only, makes it appear as new tab.
In order to add content by admin, I have created an atrribute, assigned it to General
group.
Created a CMS block at CMS > Static Blocks > Add New Block
and in the create/edit
product view, locating new attribute and populate it with the identifier of new CMS block. In my case, features_product_tab
.
When I disable the Static Block, the tab still appears on product page. And even if the content is null, its shows on page. Maybe (as is often the case) CMS block is not strictly empty and contains hidden div
or p
tags?
The code in local.xml
to display one of the tabs is
<block type="catalog/product_view_attributes" name="features_product_tab" as="features_product_tab" template="catalog/product/view/tabs/features.phtml">
<action method="addToParentGroup"><group>detailed_info</group></action>
<action method="setTitle" translate="value"><value>Features</value></action>
</block>
- Is it possible to check the
Block Status
from xml code, and show
it only if its enabled ? - How can the value of 'setTitle' be fetched from
Block Title
?
Best Answer
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.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: