1

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>
  1. Is it possible to check the Block Status from xml code, and show it only if its enabled ?
  2. How can the value of 'setTitle' be fetched from Block Title ?
5

Please only ask one question at once. Anyway, here you go:

  1. 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>
    
  2. 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 your catalog/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>
    
  • CMS block is not strictly empty and contains hidden div or p tagsas Magento does not allow saving an block without content – Slimshadddyyy Feb 16 '15 at 5:39
  • @Vikram oh yeah, you are right. I edited my answer accordingly. – Simon Feb 16 '15 at 7:46
  • @Vikram If my answer answers your initial question, consider accepting it. – Simon Feb 16 '15 at 9:45
  • block content is <p>EMPTY</p> but it does not work with the code. Moreover I am not using view.phtml but catalog/product/view/features.phtml to render the content based on block status – Slimshadddyyy Feb 16 '15 at 9:59
1

I wanna add little additional, to @Simon answer, and anwer for the question:

  1. Is it possible to check the Block Status from xml code, and show it only if its enabled ?

No. But you can check it in file catalog/product/view.phtml

<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):?>
                <!--check if is active block-->
                <?php if (Mage::getModel('cms/block')->load($alias)->getIsActive()): ?>
                    <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>

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.