Goal: After reading this tutorial Magento 2 How to get all xml loaded tree , you can output any layout xml file of any page in magento 2.
Sometime you have a desire to print all xml loaded tree to check whether your custom xml handles are loaded or not ?
For this purpose, I have written a simple module to print all xml loaded tree in a xml file, so checking your custom module xml is more easily.

The general ideas of this extension :

  • We listen to an event “layout_generate_blocks_after” and get all loaded tree from that point.
  • Save all loaded tree to an xml file.

It sounds easily right ? Here is how we create it.

The module we will create like the below image:




  1. We create a new directory Thienphucvx/Dev.
  2. Create Thienphucvx/Dev/registration.php to declare with Magento 2 about our module directory.
  3. Create Thienphucvx/Dev/etc/module.xml : To let Magento 2 know about setup version of our module
  4. Create Thienphucvx/Dev/etc/fronted/event.xml. In this file, we will listen to event “layout_generate_blocks_after
  5. Create Thienphucvx/Dev/Model/Layout.php with the content as below
  6. Set up module
    In your home website directory. enter CMD command line:
    – php bin/magento module:enable Thienphucvx_Dev
    – php bin/magento setup:upgrade
  7. Refresh the page that you want to see xml file (for example: your home page)  and check your handle xml file  in var/log/layout_block.xml .

Happy coding ! If you have any questions, please let me know.