![]() |
VOOZH | about |
This page documents the Layout XML system and block architecture in Maho's frontend rendering engine. It covers:
.phtml) files and their interaction with blocks.For information about the overall layout system architecture and how it integrates with the request flow, see Layout System (3.4) For theme structure and file organization, see Theme Architecture (6.1) For detailed block class API reference, see Block API (14.3)
Layout XML files define the structure of pages by declaring which blocks to instantiate, how they relate to each other, and which templates they use. The layout system processes XML from multiple sources and merges them based on layout handles.
Layout XML files are organized by module and theme within the design fallback system:
app/design/adminhtml/default/default/layout/
├── main.xml # Core admin layout structure
├── oauth.xml # OAuth module layouts
└── ...
Modules declare their layout files in config.xml under the layout/updates node.
Sources: app/design/adminhtml/default/default/layout/main.xml1-24 app/design/adminhtml/default/default/layout/oauth.xml1-15
Layout handles determine which XML nodes are processed for a given request. Multiple handles are dispatched per request, allowing XML from different sources to be merged into a single page structure.
| Handle Pattern | Description | Example |
|---|---|---|
default | Applied to all pages | Base structure and global components app/design/adminhtml/default/default/layout/main.xml39 |
{module}_{controller}_{action} | Specific route | adminhtml_noroute app/design/adminhtml/default/default/layout/main.xml137 |
popup | Specific layout for popups | Removes header and menu app/design/adminhtml/default/default/layout/main.xml97-104 |
editor | Handles for WYSIWYG editor | Loads TipTap assets app/design/adminhtml/default/default/layout/main.xml119-131 |
Sources: app/code/core/Mage/Core/Block/Abstract.php282-286 app/design/adminhtml/default/default/layout/main.xml39-92 app/design/adminhtml/default/default/layout/main.xml119-131
Layout XML uses specific elements to declare blocks, references, and modifications.
<block> - Block DeclarationInstantiates a block class and adds it to the layout tree.
type: Block class identifier (e.g., adminhtml/page). app/design/adminhtml/default/default/layout/main.xml40name: Unique identifier in the layout tree. app/code/core/Mage/Core/Block/Abstract.php54template: Path to .phtml file. app/code/core/Mage/Core/Block/Abstract.php29output: If set to toHtml, this block is a top-level output block. app/design/adminhtml/default/default/layout/main.xml40as: Alias used by parent blocks to reference this child. app/code/core/Mage/Core/Block/Abstract.php75<reference> - Modify Existing BlockReferences a block by name to add children or call actions without redeclaring it. app/design/adminhtml/default/default/layout/main.xml101
<action> - Call Block MethodExecutes a method on the block instance during layout generation via the Mage_Core_Block_Abstract logic. app/design/adminhtml/default/default/layout/main.xml42-46
Sources: app/design/adminhtml/default/default/layout/main.xml40-42 app/code/core/Mage/Core/Block/Abstract.php50-54
Blocks inherit from Mage_Core_Block_Abstract and specialize for different purposes.
| Class | Purpose | Template Required |
|---|---|---|
Mage_Core_Block_Abstract | Base class for all blocks | No app/code/core/Mage/Core/Block/Abstract.php33 |
Mage_Core_Block_Template | Logic for rendering .phtml files | Yes |
Mage_Core_Block_Text_List | Automatically renders all child blocks (containers) | No app/design/adminhtml/default/default/layout/main.xml70 |
Mage_Adminhtml_Block_Template | Specialized for Admin UI, includes form key support | Yes app/code/core/Mage/Adminhtml/Block/Template.php13 |
Sources: app/code/core/Mage/Core/Block/Abstract.php33-34 app/code/core/Mage/Adminhtml/Block/Template.php13-14 app/code/core/Mage/Adminhtml/Block/Widget.php13-14
Blocks follow a specific lifecycle from instantiation to HTML output, managed by Mage_Core_Model_Layout.
Sources: app/code/core/Mage/Core/Block/Abstract.php292-300 app/code/core/Mage/Core/Block/Abstract.php321-330 app/code/core/Mage/Adminhtml/Block/Template.php41-45
Blocks form a tree structure. A parent block is responsible for rendering its children, typically via $this->getChildHtml('alias') in its template. Child blocks are managed in internal arrays $_children and $_sortedChildren.
Sources: app/design/adminhtml/default/default/layout/main.xml40-91 app/code/core/Mage/Core/Block/Abstract.php85-96
Templates are PHP files with a .phtml extension. Inside the template, $this refers to the block instance associated with that template.
| Method | Source | Description |
|---|---|---|
$this->getChildHtml($name) | Mage_Core_Block_Abstract | Renders a child block by its alias app/design/frontend/base/default/template/page/3columns.phtml17 |
$this->helper($name) | Mage_Core_Block_Abstract | Instantiates a helper class app/code/core/Mage/Core/Block/Abstract.php590-597 |
$this->__($text) | Mage_Core_Helper_Abstract | Translates the provided string app/code/core/Mage/Core/Helper/Abstract.php165 |
$this->escapeHtml($data) | Mage_Core_Helper_Abstract | Escapes HTML entities app/code/core/Mage/Core/Helper/Abstract.php180 |
$this->getFormKey() | Mage_Adminhtml_Block_Template | Retrieves session form key (Admin) app/code/core/Mage/Adminhtml/Block/Template.php30-33 |
Sources: app/code/core/Mage/Core/Block/Abstract.php195-204 app/code/core/Mage/Core/Block/Abstract.php590-597 app/code/core/Mage/Core/Helper/Abstract.php165-171 app/code/core/Mage/Core/Helper/Abstract.php180-203 app/code/core/Mage/Adminhtml/Block/Template.php30-33
Blocks can be cached to avoid expensive rendering logic. Caching is controlled by properties in the block class or data set via layout XML.
setCacheLifetime(int|false). If false or null, cache is disabled. app/code/core/Mage/Core/Block/Abstract.php21setCacheKey(string). A unique string identifying the block's specific state. app/code/core/Mage/Core/Block/Abstract.php22setCacheTags(array). Tags used for mass cache invalidation. app/code/core/Mage/Core/Block/Abstract.php23Blocks use a prefix BLOCK_ for cache keys app/code/core/Mage/Core/Block/Abstract.php38 and belong to the block_html cache group app/code/core/Mage/Core/Block/Abstract.php42
Sources: app/code/core/Mage/Core/Block/Abstract.php21-23 app/code/core/Mage/Core/Block/Abstract.php38-47
Refresh this wiki