Magento2: Programmatically Create Custom Layout XML
This article shows how you can create a custom layout XML handle programmatically in your custom module in Magento 2. I will be using event observer for this. app/code/Company/Module/etc/frontend/events.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd"> <event name="layout_load_before"> <observer name="mycompany_custom_layout" instance="Company\Module\Model\Observer\CustomLayout" /> </event> </config> app/code/Company/Module/Observer/CustomLayout.php Here, I am checking if a customer is logged in or not … Read more