
Magento 2 layout XML is the set of instructions that decides which blocks and containers appear on a page, in what order, and with which templates. Files are named after layout handles, merged across modules and themes, and then modified with referenceBlock, referenceContainer, move, and the remove attribute. Hyva keeps this system and adds hyva_ prefixed handles on top.
Most layout problems on a Magento store are not exotic. A block that will not move, a removal that “comes back” after an upgrade, a page that suddenly stops being cached, a child theme that silently ignores a parent change. They nearly all trace back to a handful of rules about how layout files are named, merged, and processed. This guide walks through those rules in the order Magento applies them, then covers what is different when the storefront runs on Hyva.
How Magento chooses which layout files apply
Every request carries a list of layout handles. Adobe’s layout documentation describes three kinds:
- Page-type handles match the controller’s full action name, such as
catalog_product_vieworcheckout_cart_index. - Page handles identify one specific page by adding parameters, such as
catalog_product_view_type_simple_id_128orcms_page_view_id_home. - Arbitrary handles do not map to any page. Other handles pull them in with
<update handle="..."/>, for examplecustomer_account.
On top of those, default is applied to every page. A layout file is simply named after the handle it targets: default.xml, catalog_product_view.xml, customer_account.xml. If a file named for a handle exists in a module or theme layout folder, its instructions join the merge for that request.
This is why the first debugging question for any layout issue is “which handles are active on this page?” If your instruction lives in catalog_category_view.xml but the page is a CMS page with a category widget, it will never run.
The three layout file types
Adobe separates layout XML into three file types, and mixing them up is a common source of “my instruction is ignored” tickets.
| File type | Root node | Folder | What it controls | Allowed instructions |
|---|---|---|---|---|
| Page layout | <layout> |
view/frontend/page_layout (module) or <Vendor>_<Module>/page_layout (theme) |
The wireframe inside body: 1column, 2columns-left, 3columns | Containers only: container, referenceContainer, move, update |
| Page configuration | <page> |
view/frontend/layout or <Vendor>_<Module>/layout |
Real page content: header, footer, blocks, head assets, page metadata | block, container, referenceBlock, referenceContainer, move, head instructions |
| Generic layout | <layout> with a mandatory root container |
Same layout folder |
Non-page output such as AJAX responses, emails, HTML fragments | update, plus blocks and containers inside root |
The default frontend page layouts are empty, 1column, 2columns-left, 2columns-right, and 3columns. A page configuration file chooses one with the layout attribute on its <page> node. A custom page layout must also be declared in a layouts.xml file before the admin can offer it.
The practical rule: if you are adding a block, you are almost always editing a page configuration file. If you are adding a new column structure, you are writing a page layout. If you try to add a <block> inside a page layout file, Magento will reject it.
Containers vs blocks
Both are named nodes in the layout tree, but they behave differently.
A container is pure structure. It holds blocks and other containers, and it can wrap its children in an HTML element. Its key attributes are:
htmlTag, from a fixed list (div,main,nav,header,footer,section,aside,ul,ol, and a few others)htmlClassandhtmlId, which only work whenhtmlTagis setoutput, where1renders the children and0disables the whole containerlabel, a human description of what the container is for
An empty container renders nothing at all. That surprises people who add a container with a class and expect an empty div to appear for styling.
A block produces output. It has a PHP class (defaulting to Magento\Framework\View\Element\Template) and usually a template in Vendor_Module::path/file.phtml form. Blocks also accept:
as, an alias scoped to the parentifconfig, a system configuration path that controls whether the block renders at allcacheable, which defaults totruedisplay, covered below
Always give blocks and containers a name. Adobe notes that unnamed elements get a random name, which means nothing else can reference them later.
Ordering with before and after
Sibling order inside a parent is controlled by before and after. The rules from Adobe’s layout instruction reference are stricter than most people assume:
- A dash (
-) means “before all siblings” or “after all siblings”. - If both attributes are set,
afterwins. - If several siblings all use
-, their relative order is undefined. - If the element you reference is not under the same parent, the position is effectively random.
- If neither attribute is set, the element is non-positioned and can land anywhere that does not break the positioned elements.
When a block “jumps around” between deploys, check for two or more siblings fighting over -, or a before/after pointing at a block that lives in a different container.
referenceBlock and referenceContainer
You almost never redeclare a block that already exists. You reference it by name and change it:
<referenceBlock name="product.info.sku">
<arguments>
<argument name="css_class" xsi:type="string">sku-line</argument>
</arguments>
</referenceBlock>
This matters most in child themes. Hyva’s documentation on referencing parent theme blocks makes the point directly: a <block> tag with a name that already exists replaces the earlier definition entirely, while <referenceBlock> modifies it. Copy-pasting a parent block declaration into a child theme works on day one, but it freezes that block’s arguments. When the parent theme later adds a new argument, your copy masks it and you get a bug that nobody can reproduce on the parent theme.
Arguments are typed with xsi:type. The types you will use most are string, boolean, number, array (with nested <item> nodes), and object, which injects a view model class implementing ArgumentInterface. On Hyva, the object type is the normal way to give a template its data, which is the pattern explained in our guide to Hyva view models and moving logic out of blocks.
remove=”true” vs display=”false” vs the remove instruction
There are three ways to make something disappear, and they are not interchangeable.
| Method | What it does | PHP objects still created? | Typical use |
|---|---|---|---|
<referenceBlock name="x" remove="true"/> |
Removes the block or container and all its children from the layout | No | Permanently dropping a block or container |
<referenceBlock name="x" display="false"/> |
Hides the element and its children but keeps them in the tree | Yes | Hiding output while other code still reads the block |
<remove src="..."/> in <head> |
Removes a CSS or JS asset from the head | Not applicable | Dropping a stylesheet or script |
<referenceContainer name="x" remove="false"/> |
Cancels an earlier removal | Not applicable | Restoring something a parent theme removed |
Two details cause most of the confusion:
- The standalone
<remove>instruction only removes static assets from<head>. It does not remove blocks. Blocks and containers are removed with theremoveattribute on a reference. display="false"is ignored whenremove="true"is also set. If you need another block to call methods on the hidden block, usedisplay="false", because a removed block no longer exists.
move and the order of operations
<move> relocates an existing element:
<move element="product.info.stock.sku" destination="product.info.main" after="page.main.title"/>
It takes element and destination (both required) plus optional as, before, and after. Without a position, the moved element goes after all of its new siblings.
Two processing rules explain most “move did nothing” reports:
- If the element does not exist on that page, the move is skipped silently.
- Moves are processed before removals. If you move a block into a container that some other file removes, your block is removed with it.
So when a moved block disappears, search the active handles for a remove="true" on the destination or any of its ancestors.
Merge order: modules, themes, and the admin
Adobe documents the layout processing order roughly like this:
- Module base and area layout files are collected. Module order follows
app/etc/config.php, with ties broken alphabetically. - The theme inheritance chain is resolved, from the oldest ancestor down to the current theme.
- Each theme’s extending files are added to the list, and any overriding files replace the file they target.
- Everything in the list is merged into one tree for the request.
Layout files from disabled modules are ignored. Because module order comes from config.php, the <sequence> declared in a module’s module.xml decides whether your module’s layout runs after the module you are trying to change. If your referenceBlock targets a block declared by Magento_Catalog, declare that dependency so your file merges later.
Extending vs overriding a layout file
Extending is the default: you drop a file with the same handle name into your module or theme, and its instructions are merged with everything else. This is upgrade-safe because the original file still loads.
Overriding replaces a file outright. The paths are specific:
- To override a module’s base layout:
<theme_dir>/<Vendor>_<Module>/layout/override/base/<handle>.xml - To override a parent theme’s file:
<theme_dir>/<Vendor>_<Module>/layout/override/theme/<ParentVendor>/<parent_theme>/<handle>.xml
Adobe’s guide to overriding layouts lists the cases where overriding is appropriate, including suppressing a method call, removing block arguments, cancelling a removal, and changing handle inclusion. It also strongly recommends against renaming blocks or changing handle inheritance. In practice, an override is a fork. Every upgrade of that module now needs a manual diff of the file you replaced, so keep overrides rare and document each one.
Admin layout updates after Magento 2.3.4
Before 2.3.4, merchants could paste raw layout XML into a Custom Layout Update field on products, categories, and CMS pages. From 2.3.4, that field became a selector of predefined files. The files live in the theme and follow a naming pattern, for example catalog_product_view_selectable_<SKU>_<Name>.xml under Magento_Catalog/layout/. Category and CMS page equivalents follow the same idea.
This is a better arrangement for teams. Layout changes now live in version control and go through review, instead of sitting in the database where nobody can diff them.
cacheable=”false”: the attribute that turns off full page cache
Setting cacheable="false" on a single block makes every page that includes that block uncacheable by the full page cache. Put it on a block in default.xml and the whole storefront stops hitting Varnish.
This is one of the most expensive one-line mistakes in Magento. Personalised content should come from customer data sections or an AJAX call instead, which is covered in our explainer on full page cache, Varnish, and hole punching on Hyva. As a rule, grep every pull request for cacheable="false" and require a written reason for each one.
What changes on Hyva
Hyva does not replace Magento’s layout system. Handles, containers, blocks, references, and moves all work the same way. What changes is the template layer and how the Luma baseline is removed.
The hyva_ prefixed handles
On a store view running a Hyva theme, every active handle gets a twin with a hyva_ prefix. A page that loads default, cms_index_index, and cms_page also loads hyva_default, hyva_cms_index_index, and hyva_cms_page. Hyva’s documentation on hyva_ layout handles is explicit that these prefixed handles always load after the regular ones, so anything in a hyva_ file can override the matching standard handle.
Their main job is compatibility modules. A module can keep its Luma blocks in catalog_product_view.xml and put Hyva-specific swaps in hyva_catalog_product_view.xml. Luma store views never see the Hyva changes, which is what lets Luma and Hyva store views run side by side during a phased migration.
The base layout reset
Hyva also has to strip out the Luma layout declarations it does not use: RequireJS widgets, Knockout UI components, and their templates. Up to version 1.3.21 this was done by a parent theme called Hyva/reset. Since 1.3.21, the hyva-themes/magento2-base-layout-reset module generates those reset declarations into var/hyva-layout-resets/ instead, and Hyva’s default themes install it automatically from 1.4.0. The module ships CLI commands to generate the resets, report theme migration status, and migrate a custom theme.
For developers, the consequence is simple: on Hyva, many Luma block names you might reference no longer exist. A referenceBlock on a Luma-only block does nothing, and a move of a missing element is skipped without an error. Check the Hyva default theme’s layout files, not Luma’s, before writing an instruction.
jsLayout and UI components
Large parts of Luma’s checkout and minicart are configured through jsLayout arguments that feed Knockout UI components. Hyva does not use those components, so jsLayout changes in layout XML have no effect on a Hyva page. That logic moves into Alpine.js templates, view models, or Hyva Checkout’s own configuration. This is the single biggest adjustment for Luma developers moving to Hyva, and it is why a proper Hyva theme development estimate always includes an audit of every custom layout file.
A debugging checklist for layout problems
When an instruction does not take effect, work through this list in order:
- Confirm the handle. Make sure the file name matches a handle that is actually active on the page.
- Confirm the file type. Blocks belong in page configuration files under
layout, not inpage_layout. - Confirm the name. Element names are case-sensitive. A typo fails silently.
- Check merge order. Add the right
<sequence>tomodule.xmlif your file needs to run after another module’s. - Search for removals. A removed ancestor takes your moved or added block with it.
- Check the theme. On Hyva, confirm the block exists in Hyva’s layout, not just Luma’s, and consider whether the change belongs in a
hyva_handle. - Clear the right caches. Layout is cached in the
layoutcache type and the rendered result infull_page. Runbin/magento cache:clean layout full_pageafter layout changes. Our breakdown of Magento 2 cache types and cache tags explains whycache:cleanis the right call here rather thancache:flush.
Working with layout XML across platforms
Layout XML is a Magento concept, and it is a big part of why Magento storefronts are so customisable and also why they get messy without discipline. Teams that run more than one platform should know that the equivalent work looks different elsewhere: Liquid sections and theme blocks on Shopify storefronts, Twig blocks and template inheritance on Shopware builds, and Stencil templates on BigCommerce stores. The underlying idea of extending a parent instead of copying it holds everywhere.
On Magento and Adobe Commerce, clean layout XML is one of the first things we look at in a codebase review, because it is where upgrade pain starts. Our Magento development services cover audits, refactors, and new builds, and our Hyva development services handle Luma to Hyva layout migration, compatibility modules, and child theme architecture. You can read more about Bemeir, see the extensions and services in our technology partner ecosystem, or start a conversation from the Bemeir homepage.
FAQ
What is the difference between a container and a block in Magento 2 layout XML?
A container is structure only. It groups blocks and other containers and can wrap them in an HTML tag with a class or ID. A block produces output through a PHP class and usually a phtml template. Empty containers render nothing, while a block renders whatever its template outputs.
Why does my referenceBlock remove=”true” not work?
The usual causes are a file named for a handle that is not active on the page, a misspelled or case-mismatched block name, or a module whose layout merges before the module that declares the block. On Hyva, the block may simply not exist because it was part of the Luma layout that Hyva resets.
Should I use remove=”true” or display=”false”?
Use remove="true" when nothing needs the block. Use display="false" when you want to hide the output but other code still reads data or calls methods on that block, because display="false" keeps the PHP object in the layout tree and a removed block no longer exists.
What are hyva_ layout handles used for?
On a Hyva store view, every active handle gets a hyva_ prefixed twin that loads after the original. Compatibility modules put Hyva-only changes in those files, so Luma store views on the same installation are unaffected. That is what makes phased or mixed Luma and Hyva setups possible.
Can merchants still add layout XML from the Magento admin?
Not as free text since Magento 2.3.4. The Custom Layout Update field on products, categories, and CMS pages is now a selector of predefined layout files stored in the theme, such as catalog_product_view_selectable_<SKU>_<Name>.xml. Developers create the files, and merchants choose them in the admin.





