Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dinhkhanh/0848fc27f2d145bf885d to your computer and use it in GitHub Desktop.
Save dinhkhanh/0848fc27f2d145bf885d to your computer and use it in GitHub Desktop.
Magento - Manually add handle in controller
<?php
/**
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('customizer_index_index');
$this->loadLayoutUpdates();
$this->generateLayoutXml();
$this->generateLayoutBlocks();
$this->_isLayoutLoaded = true;
//refer 1: http://stackoverflow.com/a/3506079/904711
//refer 2: http://makandracards.com/magento/8209-adding-a-layout-handle-from-a-controller
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment