Created
December 27, 2013 07:19
-
-
Save birchestx/8143673 to your computer and use it in GitHub Desktop.
Conditionally load layouts using Observer events From http://prattski.com/2012/04/25/magento-more-flexibility-for-your-layout-updates/ http://stackoverflow.com/questions/11804575/dynamically-insert-into-layout-xml-of-magento
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In config.xml | |
<controller_action_layout_generate_xml_before> | |
<observers> | |
<add_new_layout> | |
<class>wsafreightcommon/observer</class> | |
<method>addNewLayout</method> | |
</add_new_layout> | |
</observers> | |
</controller_action_layout_generate_xml_before> | |
Observer.php | |
public function addNewLayout($observer){ | |
$layout = $observer->getEvent()->getLayout(); | |
$update = $layout->getUpdate(); | |
$action = $observer->getEvent()->getAction(); | |
$fullActionName = $action->getFullActionName(); | |
switch ($fullActionName) { | |
case 'adminhtml_sales_order_view': | |
$xml = "<reference name='root'><remove name='footer'></remove></reference>"; | |
$update->addUpdate($xml); | |
... | |
break; | |
} | |
//in case you're going to add some conditional (apply these new layout xml on these action or other things, you can modify it by yourself) | |
//here is the pieces of layout xml you're going to load (you get it from database) | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment