1

Consider i have three blocks on left sidebar namely block_1, block_2 and block_3

i can remove all of the above block by using below code

<remove name="block_1" />
<remove name="block_2" />
<remove name="block_3" />

but i dont want to use above code as blocks in my sidebar are coming dynamically. so i am looking for code which will remove all the block, something like <remove name="all" />

  • 1
    try <remove name="left"> – MeenakshiSundaram R Jul 24 '14 at 7:13
  • Have you tried the solutions below? Do they work for you? Then please consider accepting an answer. – Simon Aug 12 '14 at 7:01
3

Via layout XML (although this will remove the whole block including the container):

<remove name="left" />

Programmatically: In your config.xml, listen to the event core_block_abstract_to_html_before (this will keep the container, but will remove all child blocks):

<core_block_abstract_to_html_before>
    <observers>
        <your_extension>
            <class>your_extension/observer</class>
            <method>coreBlockAbstractToHtmlBefore</method>
        </your_extension>
    </observers>
<core_block_abstract_to_html_before>

And then in your Observer.php, unset all children if the current block is the block of the left sidebar:

public function coreBlockAbstractToHtmlBefore(Varien_Event_Observer $observer) {
    /* @var Mage_Core_Block_Abstract $block */
    $block = $observer->getEvent()->getBlock();
    if ($block->getNameInLayout() == 'left') {
        $block->unsetChildren();
    }
}
0

Technically you could try removing block left and creating it again. I haven't tried it myself but similar approaches are known to be used elsewhere.

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.