VOOZH about

URL: https://deepwiki.com/MahoCommerce/maho/6.2-layout-xml-and-blocks

⇱ Layout XML and Blocks | MahoCommerce/maho | DeepWiki


Loading...
Last indexed: 15 May 2026 (ea8ab8)
Menu

Layout XML and Blocks

Purpose and Scope

This page documents the Layout XML system and block architecture in Maho's frontend rendering engine. It covers:

  • Layout XML syntax and structure for defining page composition.
  • Block types, hierarchy, and rendering lifecycle.
  • Template (.phtml) files and their interaction with blocks.
  • Common patterns for creating custom layouts and blocks.
  • Caching mechanisms and parent-child data flow.

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 Overview

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 File Locations

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

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.

Common Handle Types

Handle PatternDescriptionExample
defaultApplied to all pagesBase structure and global components app/design/adminhtml/default/default/layout/main.xml39
{module}_{controller}_{action}Specific routeadminhtml_noroute app/design/adminhtml/default/default/layout/main.xml137
popupSpecific layout for popupsRemoves header and menu app/design/adminhtml/default/default/layout/main.xml97-104
editorHandles for WYSIWYG editorLoads TipTap assets app/design/adminhtml/default/default/layout/main.xml119-131

Handle Processing Flow


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 Syntax

Layout XML uses specific elements to declare blocks, references, and modifications.

Core XML Elements

<block> - Block Declaration

Instantiates a block class and adds it to the layout tree.

<reference> - Modify Existing Block

References a block by name to add children or call actions without redeclaring it. app/design/adminhtml/default/default/layout/main.xml101

<action> - Call Block Method

Executes 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


Block Class Hierarchy

Blocks inherit from Mage_Core_Block_Abstract and specialize for different purposes.


Key Block Types

ClassPurposeTemplate Required
Mage_Core_Block_AbstractBase class for all blocksNo app/code/core/Mage/Core/Block/Abstract.php33
Mage_Core_Block_TemplateLogic for rendering .phtml filesYes
Mage_Core_Block_Text_ListAutomatically renders all child blocks (containers)No app/design/adminhtml/default/default/layout/main.xml70
Mage_Adminhtml_Block_TemplateSpecialized for Admin UI, includes form key supportYes 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


Block Lifecycle and Rendering

Blocks follow a specific lifecycle from instantiation to HTML output, managed by Mage_Core_Model_Layout.

Rendering Sequence


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


Parent-Child Block Relationships

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.

Block Tree Example (Admin Structure)


Sources: app/design/adminhtml/default/default/layout/main.xml40-91 app/code/core/Mage/Core/Block/Abstract.php85-96


Template System

Templates are PHP files with a .phtml extension. Inside the template, $this refers to the block instance associated with that template.

Common Template Methods

MethodSourceDescription
$this->getChildHtml($name)Mage_Core_Block_AbstractRenders a child block by its alias app/design/frontend/base/default/template/page/3columns.phtml17
$this->helper($name)Mage_Core_Block_AbstractInstantiates a helper class app/code/core/Mage/Core/Block/Abstract.php590-597
$this->__($text)Mage_Core_Helper_AbstractTranslates the provided string app/code/core/Mage/Core/Helper/Abstract.php165
$this->escapeHtml($data)Mage_Core_Helper_AbstractEscapes HTML entities app/code/core/Mage/Core/Helper/Abstract.php180
$this->getFormKey()Mage_Adminhtml_Block_TemplateRetrieves 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


Block Caching

Blocks can be cached to avoid expensive rendering logic. Caching is controlled by properties in the block class or data set via layout XML.

  1. Cache Lifetime: setCacheLifetime(int|false). If false or null, cache is disabled. app/code/core/Mage/Core/Block/Abstract.php21
  2. Cache Key: setCacheKey(string). A unique string identifying the block's specific state. app/code/core/Mage/Core/Block/Abstract.php22
  3. Cache Tags: setCacheTags(array). Tags used for mass cache invalidation. app/code/core/Mage/Core/Block/Abstract.php23

Cache Keys and Tags

Blocks 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