Posted over 9 years ago. Visible to the public.

Adding A Layout Handle From A Controller

Doing this is a slight pain, to quote what Alan Storm said on StackOverflow Archive :

  1. If you add your handle before you call $this->loadLayout() from a controller it's too soon
  2. If you add your handle after you call $this->loadLayout() it's too late

So, if you really need to add a handle to a controller, you need to replace the call to $this->loadLayout() with:

Copy
$update = $this->getLayout()->getUpdate(); $update->addHandle('default'); $this->addActionLayoutHandles(); $update->addHandle('your_handle'); $this->loadLayoutUpdates(); $this->generateLayoutXml(); $this->generateLayoutBlocks(); $this->_isLayoutLoaded = true;

Owner of this card:

Avatar
Mike Whitby
Last edit:
about 8 years ago
Posted by Mike Whitby to Magento
This website uses short-lived cookies to improve usability.
Accept or learn more