![]() |
VOOZH | about |
This document explains Maho's Layout System, which controls how pages are structured and rendered in both frontend and backend (adminhtml) areas. The layout system defines which blocks appear on a page, their hierarchical relationships, and how they render HTML output through templates.
For information about theming and design packages, see Theme Architecture. For block-specific implementations in the catalog module, see Layout XML and Blocks. For the request routing that precedes layout processing, see Request Flow and Front Controller.
The layout system is a declarative XML-based framework that defines page structure. It operates in three layers:
Mage_Core_Block_Abstract app/code/core/Mage/Core/Block/Abstract.php33-34The system supports multiple stores, themes, and design packages through XML merging and fallback mechanisms managed by the design package system.
The following diagram illustrates the transition from the "Natural Language Space" (Request/Action) to the "Code Entity Space" (Models and Blocks).
Title: Layout Processing Flow
Sources: app/code/core/Mage/Core/Model/Layout.php13-20 app/code/core/Mage/Core/Block/Abstract.php33-34
Layout XML files define block structure for specific areas, modules, and pages. Files are located in app/design/{area}/{package}/{theme}/layout/*.xml. For example, the admin main layout is defined in app/design/adminhtml/default/default/layout/main.xml app/design/adminhtml/default/default/layout/main.xml1-26
The layout configuration is a merged XML tree where instructions like <block>, <reference>, and <action> are processed. The Mage_Core_Model_Layout class extends Maho\Simplexml\Config to handle this XML data app/code/core/Mage/Core/Model/Layout.php13-14
Title: Layout XML Instruction Processing
Sources: app/code/core/Mage/Core/Model/Layout.php135-202 app/code/core/Mage/Core/Model/Layout.php81-84
| Directive | Purpose | Implementation |
|---|---|---|
<block> | Creates new block instance | Mage_Core_Model_Layout::_generateBlock app/code/core/Mage/Core/Model/Layout.php211-212 |
<reference> | Modifies existing block | Mage_Core_Model_Layout::generateBlocks app/code/core/Mage/Core/Model/Layout.php193-195 |
<action> | Calls block method | Mage_Core_Model_Layout::_generateAction app/code/core/Mage/Core/Model/Layout.php197-199 |
<remove> | Removes block/reference | Mage_Core_Model_Layout::generateXml app/code/core/Mage/Core/Model/Layout.php138-142 |
<update> | Includes another handle | Mage_Core_Model_Layout_Update logic app/design/adminhtml/default/default/layout/main.xml98 |
Blocks are the workhorses of the layout system. They encapsulate logic and data for the view layer.
Mage_Core_Block_Abstract: The base class for all blocks. It provides methods for child management, caching, and the rendering lifecycle app/code/core/Mage/Core/Block/Abstract.php33-34Mage_Core_Block_Template: Extends abstract to support PHTML template rendering via the setTemplate() method app/code/core/Mage/Core/Block/Abstract.php29Mage_Adminhtml_Block_Template: A specialized block for the administrative interface app/code/core/Mage/Adminhtml/Block/Template.php12When Mage_Core_Model_Layout::addBlock() is called, it uses the configuration system to resolve the class name and instantiates the block.
Title: Block Creation Sequence
Sources: app/code/core/Mage/Core/Model/Layout.php68-74 app/code/core/Mage/Core/Block/Abstract.php195-217 app/code/core/Mage/Core/Block/Abstract.php292-297
Blocks support HTML fragment caching to improve performance.
getCacheKey(). The prefix BLOCK_ is used app/code/core/Mage/Core/Block/Abstract.php38setCacheLifetime(). A value of null or false affects the caching behavior app/code/core/Mage/Core/Block/Abstract.php21-22setCacheTags(). The default group is block_html app/code/core/Mage/Core/Block/Abstract.php23-42Sources: app/code/core/Mage/Core/Block/Abstract.php38-47
Templates are the final step in the pipeline. They are typically .phtml files located in the design folder app/design/install/default/default/template/page.phtml1-13
The rendering process involves checking for cached output before executing the block's internal logic.
toHtml(): The entry point for rendering._beforeToHtml(): A hook for final data preparation app/code/core/Mage/Adminhtml/Block/Sales/Order/Comments/View.php19-26_toHtml(): The actual rendering logic. In template blocks, this triggers the inclusion of the PHTML file._afterToHtml(): A hook for post-processing the generated HTML.Sources: app/code/core/Mage/Core/Block/Abstract.php292-297 app/code/core/Mage/Adminhtml/Block/Sales/Order/Comments/View.php19-26
Parent blocks render children using getChildHtml($alias). If no alias is provided, it renders all children app/design/adminhtml/default/default/template/page/head.phtml33
_sortedChildren: An internal array maintaining the order of child blocks app/code/core/Mage/Core/Block/Abstract.php96insert(): Adds a child block with optional positioning (before/after) app/code/core/Mage/Core/Model/Layout.php243-245Sources: app/code/core/Mage/Core/Block/Abstract.php89-96 app/code/core/Mage/Core/Model/Layout.php243-245
Mage_Core_Block_Abstract| Method | Description |
|---|---|
setLayout(Mage_Core_Model_Layout $layout) | Sets the layout instance and triggers _prepareLayout() app/code/core/Mage/Core/Block/Abstract.php292-297 |
setTemplate($template) | Sets the path to the PHTML file app/code/core/Mage/Core/Block/Abstract.php29 |
getParentBlock() | Retrieves the parent block object app/code/core/Mage/Core/Block/Abstract.php261-264 |
getRequest() | Retrieves the HTTP request object app/code/core/Mage/Core/Block/Abstract.php245-254 |
__($text) | Translates a string using the block's module context app/code/core/Mage/Core/Helper/Abstract.php165-171 |
escapeHtml($data) | Escapes HTML entities to prevent XSS app/code/core/Mage/Core/Helper/Abstract.php180-203 |
Sources: app/code/core/Mage/Core/Block/Abstract.php29 app/code/core/Mage/Core/Block/Abstract.php245-254 app/code/core/Mage/Core/Block/Abstract.php261-264 app/code/core/Mage/Core/Block/Abstract.php292-297 app/code/core/Mage/Core/Helper/Abstract.php165-171 app/code/core/Mage/Core/Helper/Abstract.php180-203
Refresh this wiki