I have added size chart tabs in magento 1.9.1 using the code below to call a CMS block into the product detail, but would like to hide the tab, if there is no data.

I am stuck and can't seem to find a method to hide the tab, if the attribute is empty.

I'm not to good with conditionals, I've tried (!empty) but maybe I'm trying the wrong place.

Any assistance is greatly appreciated.

Here's the code I am using:


<block type="catalog/product_view_attributes" name="product.sizes" as="sizes" template="catalog/product/view/sizes.phtml">
    <action method="addToParentGroup"><group>detailed_info</group></action>
    <action method="setTitle" translate="value"><value>Size Guide</value></action>

And here's the size.phtml

$_product = $this->getProduct();
$attribute = $_product->getResource()->getAttribute('sizes_table');
if ( is_object($attribute) ) {
  $identifier = $_product->getData("sizes_table");

<?php if ($_sizeBlock = Mage::app()->getLayout()->createBlock('cms/block')->setBlockId($identifier)): ?>
    <div class="std">
        <?php echo $_sizeBlock->toHtml() ?>
<?php endif; ?>
  • how you made it work ? Feb 10, 2015 at 12:38

1 Answer 1


Try this, it's a bit funky but it works. The idea is to add new tab only if sizes_table is set on the current product instance.

In your layout update file (local.xml):

    <reference name="product.info">
        <block type="foo_bar/block" name="product.sizes" as="product.sizes" />

Custom block class (app/code/local/Foo/Bar/Block/Block.php):

class Foo_Bar_Block_Block extends Mage_Cms_Block_Block
    protected function _prepareLayout()
        $product = Mage::registry('current_product');

        if ($product->getData('sizes_table')) {

            /** tab title */
            $this->setTitle($this->__('Size Guide'));

            /** static block identifier */

        return $this;

If the Size Guide tab is not added try commenting out if ($product->getData('sizes_table')) condition. If it's added after that, you'll have to find another way to retrieve the product attribute.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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