0

I want to hide the product-collateral tab present in product details page when no value is entered for that attribute. am stuck here.

The tab coding in view.phtml is this:

<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):?>
                <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 endforeach;?>
        </dl>
    <?php endif; ?>
</div>

In catalog.xml it is called like:

<block type="catalog/product_view_description" name="product.description" as="description" template="catalog/product/view/description.phtml">  
    <action method="addToParentGroup"><group>detailed_info</group></action>
    <action method="setTitle" translate="value"><value>Description</value></action>
</block>

The description.phtml is this:

<?php $_description = Mage::registry('current_product')->getDescription(); ?>
<?php if ($_description): ?>
    <div class="std">
        <?php echo $this->helper('catalog/output')->productAttribute(Mage::registry('current_product'), $_description, 'description') ?>
    </div>
<?php endif; ?>

Please guide me how to hide the tab when no value is entered in description attribute field.I dont exactly know the jquery responsible for this.

1 Answer 1

2

You can add a condition here. This will skip the tab from rendering

...

<dl id="collateral-tabs" class="collateral-tabs">
    <?php foreach ($detailedInfoGroup as $alias => $html):?>
    <?php  
        //ADD YOUR CONDITION HERE
        if($alias=="description") continue; 
        // if(trim($html)=="") continue;
    ?>
        <dt class="tab"><span><?php echo $this->escapeHtml($this->getChildData($alias, 'title')) ?></span></dt>
        ...

    ...

...

You can compare name of any tab here if($alias=="NAME_OF_TAB")

8
  • when I included this code <?php //ADD YOUR CONDITION HERE if($alias=="description") continue; ?> it is hiding the tab even when there is value.
    – Ramya
    Commented May 27, 2016 at 6:53
  • you want to hide tab, if whole description content OR HTML is empty, right ? Commented May 27, 2016 at 6:55
  • yes. When No value is entered in that attribute field it should be hidden.
    – Ramya
    Commented May 27, 2016 at 6:56
  • 1
    use if(trim($html)=="") continue; Commented May 27, 2016 at 6:58
  • 1
    Why this ans is accepted? Its not working at all.
    – Indian
    Commented Sep 20, 2017 at 11:31

Your Answer

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

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