I’ve been digging into Magento 2’s layout system, and there’s significant changes from Magento 1. Conceptually, it’s still a “nested tree” of elements, but instead of just blocks there’s now a second type of thing you can add to a layout called a container. Containers look like they’re intended to formalize the difference between content and structural blocks.
Simple enough from an end user’s point of view — but there’s a number of changes under the hood in the
Mage_Core_Model_Layout element to implement this. From an initial pass, these changes include
- The layout’s parent/child structure is now managed by a new
Mage_Data_Structureobject (stored in the
- Blocks are still block objects, but containers are not independent objects
Containers are rendered by the layout object, whereas blocks are still rendered by the
This means if you have code like this
you’re in for some refactoring, as
content is no longer a block, but instead it’s a container.
Beyond my interest in porting the world’s greatest Magento debugging extension to Magento 2, this is also interesting as PHP architecture case study.
If Magento was a java based system, my bet is containers would have simply become another type of Block object. However, because each new instantiated PHP object brings an additional bit of overhead, and Magento is the rare PHP application where the PHP code actually becomes a bottle neck, it’s easy to see why the container implementation takes a different approach.
Hat tip to @vrann for the containers pointer.