Netismine

Tips & Tricks

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

controller_action_layout_render_before
select all

event, and create this observer function:

public 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);
	}
}
select all

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

  1. Great posts! I always confused about Magento’s getsingleton method.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">