How to remove the left sidebar based on some condition written in block? I have to use the same layout xml file. Based on a condition, need to remove a block through coding. section need to be removed:

 <reference name="left">
   <block type="catalog/layer_view" name="catalog.leftnav" before="-" template="catalog/layer/view.phtml"/>

I tried with below code.


I didn't get any error but left sidebar still there. can anyone help me? Thanks.

  1. I cant access controller. If i have access for controller, then i can easily do in layout rendering section. So i added my work as module and created block. Now I need to change layout / remove left sidebar.

  2. Or is It possible to change the layout xml from block? Because i have condition statement in block. so i can choose the layout based on the condition.

Can anyone help me to fix this? Thanks

  • Try with Mage::app()->getLayout()->unsetBlock('left');
    – Sukeshini
    Dec 30, 2013 at 7:17
  • @Su123 Tried but no error and also block still exist.
    – Kumar V
    Dec 30, 2013 at 7:20
  • <remove name='catalog.leftnav'/>
    – Dexter
    Dec 30, 2013 at 8:20
  • Mage::app()->getLayout()->getUpdate()->addUpdate("<remove name=\"left\"/>");
    – Sukeshini
    Dec 30, 2013 at 8:40
  • @Su123 I have placed your code in block function. Still it not working. Can you tell me where should i add?
    – Kumar V
    Dec 30, 2013 at 12:27

2 Answers 2


If you do not want to use an observer what you could do is rewrite the block Mage_Catalog_Block_Layer_View and override the function _toHtml so that it performs the conditional check you want.

protected function _toHtml() {
    if (your conditional check) {
        return '';
    return parent::_toHtml();

you can try to listen some event like controller_action_layout_load_before and you will get layout object like

$update = $observer->getEvent()->getLayout()->getUpdate();

now you can remove/unset the block

  • I want to do in block not in controller. is there anyway?
    – Kumar V
    Dec 30, 2013 at 7:32
  • 1
    This is not in controller.Its an observer event
    – Bharath
    Dec 30, 2013 at 7:55
  • I'm new magento. I dont know where to implement your code. I can't access the controller. So i'm just doing in block and calling block in layout. Can you explain more about your answer. how to add event listener etc..,
    – Kumar V
    Dec 31, 2013 at 5:00
  • Can't you do it using xml ?
    – Mark
    May 5, 2014 at 6:47

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.