Adding A Layout Handle From A Controller

Updated . Posted . Visible to the public.

Doing this is a slight pain, to quote what Alan Storm said on StackOverflow Show archive.org snapshot :

  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:

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

Mike Whitby
Last edit
Posted by Mike Whitby to Magento (2012-04-30 13:58)