Layout Handle:-
Layout handle is a string that links an XML layout file with a specific page or group of pages. page-type layout handles: A page type identifier corresponds to the full name of the controller action.
This means we are adding layout in another layout xml using add handle.
But in this blog we are trying to add layout handle using events.
You can follow these steps:
Step1 – Firstly, create a simple module.
then create events.xml file inside [Vendor]\[Module]\[etc]/[area] path
and add below code in events.xml file
1 2 3 |
<event name="layout_load_after"> <observer name="load_custom_handler" instance="[Vendor]\[Module]\Observer\LayoutLoadBefore" /> </event> |
Step2 – create LayoutLoadBefore.php file inside.
[Vendor]\[Module]\Observer path
and add below code in LayoutLoadBefore.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<?php namespace [Vendor]\[Module]\Observer; use Magento\Framework\View\Result\Layout; class LayoutLoadBefore implements \Magento\Framework\Event\ObserverInterface { const MY_SPECIFIC_LAYOUT_HANDLE = 'my_specific_layout_handle'; /** * @param \Magento\Framework\Event\Observer $observer */ public function execute(\Magento\Framework\Event\Observer $observer) { $layout = $observer->getLayout(); $layout->getUpdate()-> addHandle(self::MY_SPECIFIC_LAYOUT_HANDLE); } } |
bluethinkinc_blog
2023-06-06