1

I am using tabs for my product view page. In my local.xml I have the following:

<catalog_product_view>
    <reference name="product.info">
        <block type="catalog/product_view_tabs" name="product.info.tabs" as="info_tabs"
                           template="catalog/product/view/tabs.phtml">
            <action method="addTab" translate="title" module="catalog">
                <alias>description</alias>
                <title>Description</title>
                <block>catalog/product_view_description</block>
                <template>catalog/product/view/description.phtml</template>
            </action>
            <action method="addTab" translate="title" module="catalog">
                <alias>videos</alias>
                <title>Videos</title>
                <block>catalog/product_view_attributes</block>
                <template>catalog/product/view/videos.phtml</template>
            </action>
        </block>
    </reference>
    <reference name="product.description">
        <block type="core/template"
               name="namespace.inline"
               as="namespace_inline"
               template="catalog/view/gallery/inline.phtml" />
    </reference>
</catalog_product_view>

In my catalog/product/view/description.phtml, I have the following:

<?php echo $this->getChildHtml('namespace_inline') ?>

But the child template does not render.

I tried switching to the default theme, and it works, but the default theme does not use tabs.

Is there something going on with the Mage_Catalog_Block_Product_View_Tabs block that does not allow it to have child blocks?

  • make sure you have product.description block is defined inside your theme's catalog.xml under catalog_product_view layout handle. – Rajeev K Tomy Sep 19 '14 at 1:24
  • that's the thing: product.description is not defined as a separate block; the only place where that block is defined is in the tabs. i tried changing my getChildHtml reference to "description" and it didn't work :\ – Laura Sep 19 '14 at 20:39
1

You are adding your block in a reference block. Since parent block of your custom block is a reference block, it is required that, this block should be defined before it get referenced in another place.

You said, when you try it in the base theme, it works. But in your custom theme its not working. So my strong believe is that, base theme holds block defines product.description inside it's catalog.xml layout file. But your custom theme is not using this name for that block, instead it may be using another name.

You need to find the block's name from catalog.xml file(in your custom theme) by referencing with it's type. (In base theme and custome theme, type of block would be same). Then use that name in your local.xml file.

  • The only place where it's defined in my custom theme is as a tab in the product.info reference above. I tried changing the name to use "product.description" in both the tab definition and in my layout update, but it still doesn't show up. I ended up resorting to <?php echo $this->getLayout()->createBlock('namespace/inline')->toHtml(); ?>, but I would have much rather used the layout XML for this type of thing :\ – Laura Sep 20 '14 at 23:42
1

To find out the name of the block added as a tab, let's take a look at Mage_Catalog_Block_Product_View_Tabs::addTab():

function addTab($alias, $title, $block, $template)
{

    if (!$title || !$block || !$template) {
        return false;
    }

    $this->_tabs[] = array(
        'alias' => $alias,
        'title' => $title
    );

    $this->setChild($alias,
        $this->getLayout()->createBlock($block, $alias)
            ->setTemplate($template)
        );
}

The second parameter of createBlock() is the name. So the name is the same as the alias, in your example description.

Using the reference in layout will still not work because when the layout tree is built, the actions are not yet executed and the description block does not exist. This means, you can not use the alias in XML as one might expect:

<reference name="description">
    <block type="core/template"
           name="namespace.inline"
           as="namespace_inline"
           template="catalog/view/gallery/inline.phtml" />
</reference>

What should work instead is creating the complete description block without reference and replace the tab child using another action, so that it happens after the addTab action has been executed:

<block type="catalog/product_view_description"
           name="product.description"
           template="catalog/product/view/description.phtml">
    <block type="core/template"
           name="namespace.inline"
           as="namespace_inline"
           template="catalog/view/gallery/inline.phtml" />
</block>
<reference name="product.info.tabs">
    <action method="setChild">
        <alias>description</alias>
        <block>product.description</block>
    </action>
</reference>

To not initialize the description block twice, you can additionally replace the original tab with a dummy placeholder, only alias and title matter:

        <action method="addTab" translate="title" module="catalog">
            <alias>description</alias>
            <title>Description</title>
            <block>core/text</block>
        </action>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.