In this tutorial we add a "Why buy from us" panel to Hyvä product pages: a list of store benefits managed in a ViewModel, styled with Tailwind and with a small Alpine.js interaction. Along the way you will see the three building blocks of almost every Hyvä customisation — layout XML, a ViewModel and a template.
You need a Hyvä child theme (see our Hyvä installation guide) and a small module, here MageServices_HyvaDemo.
Step 1: The ViewModel
<?php
declare(strict_types=1);
namespace MageServices\HyvaDemo\ViewModel;
use Magento\Framework\View\Element\Block\ArgumentInterface;
class StoreBenefits implements ArgumentInterface
{
/**
* @return array<int, array{title: string, text: string}>
*/
public function getBenefits(): array
{
return [
['title' => (string) __('Free UK delivery'), 'text' => (string) __('On all orders over £50.')],
['title' => (string) __('30-day returns'), 'text' => (string) __('Change your mind? Send it back free of charge.')],
['title' => (string) __('Expert support'), 'text' => (string) __('Talk to our team Monday to Friday.')],
];
}
}
In a real project these values would come from configuration or a CMS block, but keeping them in a ViewModel shows the pattern.
Step 2: Add the Block With Layout 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="product.info.main">
<block name="mageservices.store.benefits"
template="MageServices_HyvaDemo::product/store-benefits.phtml"
after="-"/>
</referenceContainer>
</body>
</page>
Hyvä loads layout handles prefixed with hyva_ only on Hyvä themes. Using hyva_catalog_product_view.xml keeps this block off any Luma store views on the same installation.
Step 3: The Template
<?php
declare(strict_types=1);
use Hyva\Theme\Model\ViewModelRegistry;
use Magento\Framework\Escaper;
use MageServices\HyvaDemo\ViewModel\StoreBenefits;
/** @var Escaper $escaper */
/** @var ViewModelRegistry $viewModels */
$benefits = $viewModels->require(StoreBenefits::class)->getBenefits();
?>
<section class="mt-8 rounded-lg border border-gray-200 bg-white p-6"
aria-labelledby="store-benefits-title"
x-data="{ active: 0 }">
<h2 id="store-benefits-title" class="text-lg font-semibold text-gray-900">
<?= $escaper->escapeHtml(__('Why buy from us')) ?>
</h2>
<ul class="mt-4 divide-y divide-gray-100">
<?php foreach ($benefits as $index => $benefit): ?>
<li class="py-3">
<button type="button"
class="flex w-full items-center justify-between text-left font-medium text-gray-800"
@click="active = active === <?= (int) $index ?> ? null : <?= (int) $index ?>"
:aria-expanded="(active === <?= (int) $index ?>).toString()">
<?= $escaper->escapeHtml($benefit['title']) ?>
<span aria-hidden="true" x-text="active === <?= (int) $index ?> ? '−' : '+'"></span>
</button>
<p class="mt-2 text-sm text-gray-600" x-show="active === <?= (int) $index ?>" x-cloak>
<?= $escaper->escapeHtml($benefit['text']) ?>
</p>
</li>
<?php endforeach; ?>
</ul>
</section>
We use Hyvä's $viewModels registry instead of a layout argument, escape every value, and cast loop indexes to integers before writing them into Alpine expressions.
Step 4: Make Tailwind See Your Module
Tailwind only generates classes it finds in scanned files. Add your module to the child theme's hyva.config.json so its templates are included, then rebuild:
{
"tailwind": {
"include": [
{ "src": "vendor/hyva-themes/magento2-default-theme" },
{ "src": "app/code/MageServices/HyvaDemo" }
]
}
}
cd app/design/frontend/MageServices/hyva-child/web/tailwind
npm run build
cd -
bin/magento cache:flush
Step 5: Overriding a Hyvä Core Template
To change an existing Hyvä template, copy it into your child theme using the module name as the folder:
mkdir -p app/design/frontend/MageServices/hyva-child/Magento_Catalog/templates/product/view
cp vendor/hyva-themes/magento2-default-theme/Magento_Catalog/templates/product/view/<template>.phtml \
app/design/frontend/MageServices/hyva-child/Magento_Catalog/templates/product/view/
Override as few templates as possible. Each override must be reviewed when Hyvä releases an update, so prefer adding blocks with layout XML or changing data in a ViewModel or plugin when you can.
Checklist for Hyvä Templates
- Logic in ViewModels, markup in templates.
- Every dynamic value escaped with the right
$escapermethod. - Full Tailwind class names, never built dynamically.
- Accessible markup: real buttons,
aria-expanded, labelled sections. - Small Alpine components; no jQuery.
Making It Configurable
To let the marketing team change the benefits without a deployment, replace the hard-coded array with values from a CMS block or store configuration. A simple approach is a configuration field per benefit read through a typed Config class in the ViewModel; for richer content, render a CMS block whose content editors manage in Page Builder. The template stays the same — only the data source changes.
Frequently Asked Questions
What is the hyva_ layout handle prefix?
Hyvä adds layout handles prefixed with hyva_ on Hyvä themes, so modules can add Hyvä-specific layout without affecting Luma store views.
Where are Hyvä templates located?
In vendor/hyva-themes/magento2-default-theme, organised by module, for example Magento_Catalog/templates.
Do I need a Block class for Hyvä templates?
Rarely. Use the default Template block and ViewModels from the $viewModels registry.
Building a Hyvä store?
Our Hyvä specialists build themes, components and compatibility modules.
Written by the Magento Services engineering team — Magento 2, Adobe Commerce and Hyvä specialists since 2014. We write about problems we solve on real client stores.