Google logo
4.9 on Google
Get a free Magento audit

Recommendations on page speed, accessibility issues, and real user experience data

Skip to main article

Layout handles in magento design

Layout handles in magento design
10 mins

Develo is a leading Magento agency and eCommerce web development company based in Birmingham, in the UK, serving clients globally since 2010.

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

$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

createBlock($type, $name='', array $attributes = array())

or modify loaded blocks

getBlock($name)

The main method of interest is

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

getHandles()

we can fetch all layout handles. This returned the following layout handles.

array (size=5)
string 'default' (length=7)
string 'STORE_default' (length=13)
string 'THEME_frontend_gravdept_custom' (length=30)
string 'doodletool_index_index' (length=22)
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.

$this->loadLayout(); 
var_dump($this->getLayout()->getUpdate()->getHandles()); 
die;

If you enjoyed this article, read the other Blogs from our Magento development agency or browse the site to see what else we do with Adobe Commerce, Magento Audits and more.

Last updated: April 16, 2024

Get in touch for help with your latest Magento or eCommerce project.