Tips & Tricks
-
Aug 26
2011 -
Remove head block from page
When developing a Magento custom module that should use an AJAX response of a page that’s bigger then a few blocks, you’d probably like to have all those script files removed from head. Now, you can either unset head block entirely, or just remove the script files. What you need to do is to create an observer on
select allcontroller_action_layout_render_before
event, and create this observer function:
select allpublic function removeHead() { if (Mage::app()->getRequest()->getModuleName() == "lazyload") { //put your module/controller/action name here so you don't remove head for every single page $layout = Mage::getSingleton('core/layout'); $layout->unsetBlock('head'); /* second level of destruction - because this block has two lives .. like a final queen in an arcade */ $head = $layout->getBlock('root')->getChild('head'); if (is_object($head)) { $head->setData('items',array()); $layout->getBlock('root')->setChild('head',$head); } /* third level of destruction - if the bitch respawns */ //$layout->getBlock('root')->setChild('head', new Mage_Core_Block_Template); } }
take a look at what it does, might give you some more ideas on how to battle the pest.
1 comment


One Response to Remove head block from page
Great posts! I always confused about Magento’s getsingleton method.