Skip to content

Instantly share code, notes, and snippets.

@eniuz
Forked from molotovbliss/gist:4f71f6242a16fa894a92
Created December 7, 2015 09:03
Show Gist options
  • Save eniuz/e30de10bf688a702272f to your computer and use it in GitHub Desktop.
Save eniuz/e30de10bf688a702272f to your computer and use it in GitHub Desktop.
Debugging Layout XML issues
Source: https://magento.stackexchange.com/questions/95/debugging-layout-xml-loading
You can log the compiled layout XML directives which are used to generate blocks. Create an observer on controller_action_layout_generate_blocks_before, and in the observer method log the update XML from the transported layout object:
public function logCompiledLayout($o)
{
$req = Mage::app()->getRequest();
$info = sprintf(
"\nRequest: %s\nFull Action Name: %s_%s_%s\nHandles:\n\t%s\nUpdate XML:\n%s",
$req->getRouteName(),
$req->getRequestedRouteName(), //full action name 1/3
$req->getRequestedControllerName(), //full action name 2/3
$req->getRequestedActionName(), //full action name 3/3
implode("\n\t",$o->getLayout()->getUpdate()->getHandles()),
$o->getLayout()->getUpdate()->asString()
);
// Force logging to var/log/layout.log
Mage::log($info, Zend_Log::INFO, 'layout.log', true);
}
Output will be similar to:
2013-01-23T16:24:26+00:00 INFO (6):
Request: cms
Full Action Name: cms_index_index
Handles:
default
cms_page
STORE_default
THEME_frontend_default_default
cms_index_index
page_two_columns_right
customer_logged_out
Update XML:
<block name="formkey" type="core/template" template="core/formkey.phtml"/>
<label>All Pages</label>
<!-- ... ->
------------------------------------------------------
You can retrieve all the layout handles in your controller by doing this:
var_dump($this->getLayout()->getUpdate()->getHandles());
Or anywhere (as long as the layout has been initialized) using this:
var_dump(Mage::app()->getLayout()->getUpdate()->getHandles());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment