One interesting thing about Magento 2’s refactored layout system is how it enables multiple XML trees modifying one global structure object. The layout builder for page objects
#File: vendor/magento/framework/View/Page/Builder.php
protected function generateLayoutBlocks()
{
$this->readPageLayout();
return parent::generateLayoutBlocks();
}
/**
* Read page layout and write structure to ReadContext
* @return void
*/
protected function readPageLayout()
{
$pageLayout = $this->getPageLayout();
if ($pageLayout) {
$readerContext = $this->layout->getReaderContext();
$this->pageLayoutReader->read($readerContext, $pageLayout);
}
}
defines a generateLayoutBlocks that will load a separate XML tree (the files in page_layout folders, I belive), and pass that XML tree through the the reader/schedule objects. It then calls the parent generateLayoutBlocks method, which handles loading, merging, read scheduling, and generating blocks from the files in the layout folders.
Two separate XML trees, both modifying the same layout.