Magento – Remove all the blocks from left sidebar

layout-updatesidebar

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" />

Best Answer

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();
    }
}