Magento 2 Experten — Hyvä Theme, Tailwind CSS & SEO aus einer Hand ›

Layout XML in Hyvä: Blocks, Containers, and the getChildNames() Iteration

Layout XML in Hyvä: Blocks, Containers, and the getChildNames() Iteration

~7 Min. Lesezeit Zuletzt aktualisiert am August 9, 2026

Layout XML is one of the areas where Hyvä differs least from classic Magento - <block>, <container>, <referenceBlock> all work exactly as you'd expect. The difference lies in how templates later output their child blocks.

Blocks and containers, briefly recapped

A container is a pure placeholder with no template of its own - it just defines where something is allowed to appear. A block is tied to a class and usually a template, and actually renders content. Both are controlled via layout handles that match URLs or controller actions.

app/code/Mironsoft/TeamPage/view/frontend/layout/team_index_index.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="content">
            <block class="Magento\Framework\View\Element\Template"
                   name="team.page"
                   template="Mironsoft_TeamPage::team/index.phtml">
                <arguments>
                    <argument name="team_view_model" xsi:type="object">Mironsoft\TeamPage\ViewModel\TeamMembers</argument>
                </arguments>
            </block>
        </referenceContainer>
    </body>
</page>

content is the default container that holds every page's main content - exactly like in any other Magento theme. What stands out here is the <argument> with xsi:type="object": this is how a ViewModel gets bound to the block, instead of writing a dedicated block class (more on that in chapter 7).

getChildNames(): the Hyvä standard iteration

When a template needs to output several child blocks (say, a row of widgets in a sidebar), Hyvä consistently uses the same iteration that already exists in classic Magento - $block->getChildNames() followed by $block->getChildHtml($name). This pattern is not replaced by Hyvä, it's kept as-is:

Example: iterating over child blocks
<?php
/** @var \Magento\Framework\View\Element\Template $block */
?>
<div class="grid grid-cols-1 gap-6 md:grid-cols-3">
    <?php foreach ($block->getChildNames() as $childName): ?>
        <?= $block->getChildHtml($childName) ?>
    <?php endforeach; ?>
</div>

Tipp: This pattern shows up in many standard Hyvä templates, for instance in the footer or the category page sidebar. If you're reading an existing Hyvä template and spot getChildNames(), you immediately know: additional blocks are being hooked in via Layout XML, without the template itself needing to know which ones.

referenceBlock, before/after, and move

<referenceBlock> for adjusting existing blocks, before/after for ordering sibling blocks, and <move> for moving a block into a different container also work unchanged. An example that removes a default block:

<referenceBlock name="catalog.compare.sidebar" remove="true" />

Handles for our later team page

The file name team_index_index.xml in the example above follows the standard Magento convention [frontName]_[controllerFolder]_[actionMethod].xml. Once we create the actual route and controller in chapter 18, this handle gets loaded automatically for the matching URL - Magento looks it up without us having to "wire it up" anywhere explicitly.