Update cookies preferences

Layout handles in magento design

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.

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


Luke

Luke Collymore
Director and Solution Specialist

Develo is a leading Magento agency and eCommerce web development company based in Birmingham, in the UK, serving clients globally since 2010. Our Blog covers topics around the array of services we offer including Magento web development, Hyvä themes development, Adobe Commerce, PunchOut catalogues, ERP integrations and much more. To speak to a friendly member of the team about your next project, contact us here.



...
Luke

share:

Ready to start your next project?

See how we can help you accelerate your business