1

In our Magento store we offer two kinds of products, each with their own root categories. I want to add CMS Static Blocks as custom tabs on product detail pages that are dependent on which category the product is under.

I know how to create tabs in the view.phtml template, but how can I make it so that:

  • Block 1 appears on product detail pages under root Category 1
  • Block 2 appears on product detail pages under root Category 2

I think it is possible with XML layout updates to remove and append tabs, but how do I append the blocks to the layout?

Micha
  • 11
  • 5

1 Answers1

1

Overview

If I am understanding your question correctly, you want to add a custom tab on the product detail page when viewing the product under your two special categories (category1 and category2).

The tabs on the product detail page are of type catalog/product_view_tabs which normally maps to the class Mage_Catalog_Block_Product_View_Tabs. This block does provide a way to add new tabs through its addTab() method, but it seems that this method assumes a template will be used, which unfortunately prevents using a CMS Static Block with this method.

A Possible Solution

If you are able to put your content from the two static blocks into two template files instead, you could do this using layout XML updates on the categories themselves. I will outline the process you would use in this scenario:

  1. Navigate to Catalog > Categories > Manage Categories in Magento Admin and click on category1 in the tree.
  2. Open the Custom Design tab.
  3. Set “Apply To Products” to Yes.
  4. Now add the layout update for that category’s products that should have the custom tab under “Custom Layout Update”:

<reference name="content">
    <reference name="product.info.tabs">
        <action method="addTab" translate="title">
            <alias>block1</alias>
            <title>Block 1</title>
            <block>core/template</block>
            <template>catalog/product/view/block1.phtml</template>
        </action>
    </reference>
</reference>

It should look something like this: enter image description here

Then just repeat the same steps for category2. The key to this solution working is to get your two template files block1.phtml and block2.phtml into the path: app/design/frontend/base/default/template/catalog/product/view/.

fantasticrice
  • 1,631
  • 1
  • 21
  • 31
  • hello @fantasticrice ! Thanks for your help! Is it possible that the reference name changed by using a custom template? i try to add this xml update to the categories but magento dont add a tab. maybe i had to modify your xml code? – Micha May 19 '15 at 02:01
  • @Micha - My solution assumes standard templates, wouldn't know how to help with your custom code. – fantasticrice May 19 '15 at 03:37