6

How do I remove a block from a group?

In catalog.xml there are (around line 210) actions 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>
</block>

So product.info gets a group called detailed_info with the blocks product.description and product.attributes.

As far as I know I can remove a whole block with

<action method="unsetChild"><name>NAME</name></action>

But that does not work for groups.

In app/code/core/Mage/Core/Block/Abstract.php there are the implementations for these actions. Methods like addToParentGroup() and addToChildGroup() as well as setChild() and unsetChild(). But there are no methods like removeFromParentGroup() or removeFromChildGroup().

How do I remove a block from such a group?

Ideas:

  • Copy the whole catalog.xml to my theme and delete that line from it.
  • Make a rewrite for app/code/core/Mage/Core/Block/Abstract.php in an own module to add methods to remove blocks from a group

The first idea is the least I would want to do and I would be reluctant to do the second.

Is there any standard magento way to do this?

1
  • Have you tried the solution below? Does it work for you? Then please consider accepting the answer.
    – Simon
    Commented Aug 12, 2014 at 7:04

2 Answers 2

7

You can do the following in your local.xml:

<reference name="product.info">
    <action method="unsetChild">
        <alias>description</alias>
    </action>
    <action method="insert">
        <block>product.description</block>
    </action>
</reference>

or for the product attributes respectively:

<reference name="product.info">
    <action method="unsetChild">
        <alias>additional</alias>
    </action>
    <action method="insert">
        <block>product.attributes</block>
    </action>
</reference>

When you do this, the block will not be rendered in the group, but you are able to render it elsewhere.

1
  • It does indeed what was asked. Unfortunately it destroys some special product views that I have where I'm using $this->helper('catalog/output')->productAttribute($_product, $_product->getDescription(), 'description'). The whole layout gets destroed and I have no idea what it could be. I found another solution, which is only a workaround. But your solution should fit most needs.
    – Akerus
    Commented Aug 19, 2014 at 8:21
1

I found a workaround for that problem (which I actually needed, because of special product views).

The original Magento-Way of displaying the group is:

<?php foreach ($this->getChildGroup('detailed_info', 'getChildHtml') as $alias => $html):?>
    <div class="box-collateral <?php echo "box-{$alias}"?>">
        <?php if ($title = $this->getChildData($alias, 'title')):?>
        <h2><?php echo $this->escapeHtml($title); ?></h2>
        <?php endif;?>
        <?php echo $html; ?>
    </div>
<?php endforeach;?>

By adding a check to the alias of the child block the output can be omitted:

<?php foreach ($this->getChildGroup('detailed_info', 'getChildHtml') as $alias => $html):?>
    <?php if($alias != 'description'): ?>
        <div class="box-collateral <?php echo "box-{$alias}"?>">
            <?php if ($title = $this->getChildData($alias, 'title')):?>
                <h2><?php echo $this->escapeHtml($title); ?></h2>
            <?php endif;?>
            <?php echo $html; ?>
        </div>
    <?php endif; ?>
<?php endforeach;?> 

This workaround is useful if you have to use the description block in a normal way at another point. If not, be shure to check out the solution from Simon.

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.