I recently helped debug an issue in Magento where a block wasn’t being added for the Index action of a custom controller. As our usual weapon of choice Alan Storms commerce bug wasn’t installed finding out why the block wasn’t being added to the layout was a little difficult. To solve this I had a look a the layout object from the controller
1 2 3 |
$this->getLayout() |
This returned the layout model object (Mage_Core_Model_Layout), this layout model is useful if your looking to create instances of blocks
1 2 3 |
createBlock($type, $name='', array $attributes = array()) |
or modify loaded blocks
1 2 3 |
getBlock($name) |
The main method of interest is
1 2 3 |
getUpdate() |
which returns an instance of the loaded layout update model (Mage_Core_Model_Layout_Update), This model stores all loaded handles used for the current layout, so by using
1 2 3 |
getHandles() |
we can fetch all layout handles. This returned the following layout handles.
1 2 3 |
array (size=5) 0 => string 'default' (length=7) 1 => string 'STORE_default' (length=13) 2 => string 'THEME_frontend_gravdept_custom' (length=30) 3 => string 'doodletool_index_index' (length=22) 4 => string 'customer_logged_out' (length=19) |
Comparing the above handles to the xml used I can see they were trying to load designtool_index and not designtool_index_index. Problem solved and on to the next one.
So to find out the layout handles used add the following code to the controller after a call to load the layout.
1 2 3 |
$this->loadLayout(); var_dump($this->getLayout()->getUpdate()->getHandles()); die; |