This skill helps you create custom Hyvä CMS components for Magento 2 by guiding module setup, components.json, and PHTML templates.
npx playbooks add skill hyva-themes/hyva-ai-tools --skill hyva-cms-component
This skill guides the interactive creation of custom Hyvä CMS components for Magento 2. It supports creating components in new or existing modules, with field presets for common patterns and automatic setup:upgrade execution.
Command execution: For commands that need to run inside the development environment (e.g., bin/magento), use the hyva-exec-shell-cmd skill to detect the environment and determine the appropriate command wrapper.
Skill deps (read via <skill_path>/../{name}/SKILL.md, where <skill_path> is the directory containing this SKILL.md file): hyva-exec-shell-cmd, hyva-create-module, hyva-cms-components-dump, hyva-render-media-image
Non-interactive runs: If the user cannot be asked (subagent or non-interactive run), take the inputs from the request. Stop and report what is missing if any of these were not given: the target module (or the vendor name for a new module), the component name and label, and the fields (a preset name or a field list). Choose the category from the component's purpose, and create a single template without variants unless variants were requested.
If not already specified in the prompt, ask the user where to create the component:
Option A: New Module
Ask for both values (do not assume defaults without asking):
Acme) - Required, no default. Do not suggest a Vendor name, prompt for user input.CmsComponents as default so user can press Enter to acceptThen use the hyva-create-module skill with:
dependencies: ["Hyva_CmsBase"]composer_require: {"hyva-themes/commerce-module-cms": "^1.0"}Option B: Existing Module
app/code/, vendor/, or custom location)Hyva_CmsBase as a dependency in etc/module.xml. If not present, add it.hyva-themes/commerce-module-cms as a dependency in composer.json. If not present, add it.Gather component information:
feature_card)Step 4a: Identify icons already in use
Use the hyva-cms-components-dump skill to dump all current CMS components. Extract all icon values from the output to build a list of icons already in use by existing components.
Step 4b: Find available lucide icons
List the SVG files in vendor/hyva-themes/magento2-theme-module/src/view/base/web/svg/lucide/ to get the full set of available icons.
Step 4c: Select the best fitting icon
From the available lucide icons that are NOT already in use by another component:
shopping-cart.svg for cart-related, image.svg for image-related, layout-grid.svg for grid layouts)Hyva_Theme::svg/lucide/[icon-name].svgIf no suitable unused icon can be found, or if the lucide directory doesn't exist, leave the icon property unset.
Offer field presets or custom field creation. See references/field-types.md "Field Presets" section for available presets (Basic Card, Image Card, CTA Block, Text Block, Feature Item, Testimonial, Accordion Item) or allow custom field definition.
Authoritative field types: prefer the project's live list when available — runbin/magento hyva:cms:list-fields (core + custom field types) via thehyva-exec-shell-cmd wrapper. Fall back to references/field-types.md only when the
command is unavailable.
For custom fields, iterate through each field asking:
references/field-types.md)attributes.required, NOT as a direct field propertyattributes object)Ask if the component needs template variants:
references/variant-support.md for configuration details.Create the required files:
The hyva-create-module skill creates the base module structure. Then add the CMS-specific directories:
app/code/[Vendor]/[Module]/
├── registration.php # Created by hyva-create-module
├── composer.json # Created by hyva-create-module
├── etc/
│ ├── module.xml # Created by hyva-create-module
│ └── hyva_cms/
│ └── components.json # Create this
└── view/
└── frontend/
└── templates/
└── elements/
└── [component-name].phtml (or [component-name]/ for variants)
Create or update:
etc/hyva_cms/components.json (merge with existing if present)view/frontend/templates/elements/[component-name].phtmlAfter creating files, run bin/magento setup:upgrade using the appropriate command wrapper detected by the hyva-exec-shell-cmd skill.
{
"[component_name]": {
"label": "[Label]",
"category": "[Category]",
"template": "[Vendor]_[Module]::elements/[component-name].phtml",
"content": {
// Generated fields
},
"design": {
"includes": [
"Hyva_CmsBase::etc/hyva_cms/default_design.json",
"Hyva_CmsBase::etc/hyva_cms/default_design_typography.json"
]
},
"advanced": {
"includes": [
"Hyva_CmsBase::etc/hyva_cms/default_advanced.json"
]
}
}
}
IMPORTANT: Only specific properties are allowed at the component level. See references/component-schema.md for the complete schema reference.
Key properties: label (required), category, template, icon, children, require_parent, content, design, advanced, disabled, custom_properties.
Invalid properties that will cause schema errors:
hidden - Does not exist. Use require_parent: true for child-only components, or disabled: trueIMPORTANT: children is a ROOT-LEVEL component property, NOT a field type within content, design, or advanced.
INCORRECT ❌:
{
"my_component": {
"content": {
"items": {
"type": "children",
"label": "Items"
}
}
}
}
CORRECT ✅:
{
"my_component": {
"label": "My Component",
"children": {
"config": {
"accepts": ["child_component"],
"max_children": 10
}
},
"content": {
"title": {
"type": "text",
"label": "Title"
}
}
}
}
In templates, access children via $block->getData('children'), NOT via a custom field name.
IMPORTANT: Field validation attributes like required must be placed in the attributes object, NOT as direct field properties.
INCORRECT ❌:
{
"title": {
"type": "text",
"label": "Title",
"required": true
}
}
CORRECT ✅:
{
"title": {
"type": "text",
"label": "Title",
"attributes": {
"required": true
}
}
}
Other validation attributes that go in attributes:
required (boolean)minlength / maxlength (string)min / max (for numbers)pattern (regex string)placeholder (string)comment (help text)For components that should only be used as children of other components (like list items), use require_parent: true:
{
"my_list_item": {
"label": "My List Item",
"category": "Elements",
"require_parent": true,
"template": false,
"content": {
"title": {"type": "text", "label": "Title"}
}
},
"my_list": {
"label": "My List",
"category": "Elements",
"template": "Vendor_Module::elements/my-list.phtml",
"children": {
"config": {
"accepts": ["my_list_item"]
}
}
}
}
When template: false, the parent component renders the child data directly (NOT using $block->createChildHtml()). See "Rendering Children with template: false" below.
Every template must start with this header:
<?php
declare(strict_types=1);
use Hyva\CmsLiveviewEditor\Block\Element;
use Hyva\Theme\Model\ViewModelRegistry;
use Magento\Framework\Escaper;
/** @var Element $block */
/** @var Escaper $escaper */
/** @var ViewModelRegistry $viewModels */
Additional requirements:
$block->getEditorAttrs() on root element$block->getEditorAttrs('field_name') on editable elements$escaper->escapeHtml() and $escaper->escapeHtmlAttr()Text fields:
$title = $block->getData('title');
// In template:
<?php if ($title): ?>
<h2 <?= /** @noEscape */ $block->getEditorAttrs('title') ?>>
<?= $escaper->escapeHtml($title) ?>
</h2>
<?php endif; ?>
Richtext/HTML fields:
$content = $block->getData('content');
// In template (no escaping for richtext):
<?php if ($content): ?>
<div <?= /** @noEscape */ $block->getEditorAttrs('content') ?>>
<?= /** @noEscape */ $content ?>
</div>
<?php endif; ?>
Image fields:
Use the hyva-render-media-image skill for rendering images. It provides the complete API reference and code patterns for the \Hyva\Theme\ViewModel\Media view model.
Add these imports when rendering images:
// Additional imports for templates with images:
use Hyva\Theme\ViewModel\Media;
/** @var Media $mediaViewModel */
$mediaViewModel = $viewModels->require(Media::class);
The data from $block->getData('image') can be passed directly to getResponsivePictureHtml():
$image = $block->getData('image');
// In template:
<?php if ($image): ?>
<?= /** @noEscape */ $mediaViewModel->getResponsivePictureHtml(
$image,
['class' => 'w-full h-auto', 'loading' => 'lazy']
) ?>
<?php endif; ?>
For responsive images with separate desktop and mobile sources, see the hyva-render-media-image skill.
Link fields:
$link = $block->getData('link');
$linkData = $link ? $block->getLinkData($link) : null;
// In template:
<?php if ($linkData): ?>
<a href="<?= $escaper->escapeUrl($linkData['url']) ?>"
<?php if (!empty($linkData['target'])): ?>target="<?= $escaper->escapeHtmlAttr($linkData['target']) ?>"<?php endif; ?>>
<?= $escaper->escapeHtml($linkData['title'] ?: 'Read more') ?>
</a>
<?php endif; ?>
Boolean fields:
$showTitle = (bool) $block->getData('show_title');
// In template:
<?php if ($showTitle && $title): ?>
<!-- title markup -->
<?php endif; ?>
Select fields:
$style = $block->getData('style') ?: 'default';
$styleClasses = match($style) {
'primary' => 'bg-blue-600 text-white',
'secondary' => 'bg-gray-200 text-gray-800',
default => 'bg-white text-gray-600'
};
Children fields (with their own templates):
When child components have their own templates (default behavior), use $block->createChildHtml():
$children = $block->getData('children') ?: [];
// In template:
<?php foreach ($children as $index => $child): ?>
<?= /** @noEscape */ $block->createChildHtml($child, 'child-' . $index) ?>
<?php endforeach; ?>
Rendering Children with template: false:
When child components have "template": false, the parent component renders them directly. Child data is flat - field values are directly on the child array, NOT nested under a content key.
$children = $block->getData('children') ?: [];
// In template - iterate and access child data directly:
<?php foreach ($children as $elementData): ?>
<?php
// Access fields directly on $elementData (NOT $elementData['content']['field'])
$image = $elementData['image'] ?? null;
$title = $elementData['title'] ?? '';
$description = $elementData['description'] ?? '';
// Each child has a 'uid' for editor attributes
$childUid = $elementData['uid'];
?>
<div <?= /** @noEscape */ $block->getEditorAttrs('', $childUid) ?>>
<?php if (!empty($image['src'])): ?>
<?php // For image rendering patterns, see the hyva-render-media-image skill ?>
<?= /** @noEscape */ $mediaViewModel->getResponsivePictureHtml(
[$block->getResponsiveImageData($image)],
['alt' => $image['alt'] ?? '', 'class' => 'w-full h-auto', 'loading' => 'lazy']
) ?>
<?php endif; ?>
<p <?= /** @noEscape */ $block->getEditorAttrs('title', $childUid) ?>>
<?= $escaper->escapeHtml($title) ?>
</p>
</div>
<?php endforeach; ?>
Key points for template: false children:
$elementData['field_name'], NOT $elementData['content']['field_name']uid property for editor attributes$block->getEditorAttrs('field_name', $childUid) to enable live editing of child fields$block->getEditorAttrs('', $childUid) on the child's root element!empty($image['src']) and use $block->getResponsiveImageData($image) to process the image datahyva-render-media-image skillreferences/critical-patterns.md: read before generating any component. Correct children configuration (root-level vs field type), field validation with attributes, default value syntax, and a checklist to run before generating.references/example-component.md: complete Feature Card example with components.json, a PHTML template using all field types, the supporting module files and the directory structure. Read to see how the pieces fit together.references/field-types.md: all field types with configuration syntax and examples, validation attributes, conditional visibility (show_if/hide_if) and field presets. Read when generating field configurations.references/variant-support.md: directory structure, components.json configuration and template patterns for variants. Read when the component needs multiple layout options.references/troubleshooting.md: schema validation errors, component not visible in the editor, template not rendering, live editor not working, image display issues, and fallbacks when dependent skills are unavailable. Read when an error occurs.assets/templates/component/template.phtml.tpl: base PHTML structure for CMS components. Placeholders: {{CONTENT_FIELDS}} (PHP variable declarations) and {{TEMPLATE_BODY}} (HTML template content).The Hyvä CMS schema is project-version-dependent. **Prefer the live schema from the
installed Hyvä Commerce package:** ifvendor/hyva-themes/commerce-module-cms/src/liveview-editor/etc/hyva_cms/jsonschema/
exists, read its JSON files directly (no interpreter needed) for this project's
authoritative component and field declarations:
component-declaration.json — valid component-level propertiescomponent-field-declaration.json — field declaration properties, field types, validation attributesOnly when Hyvä Commerce is not installed, fall back to the bundledreferences/component-schema.md. Read either source when validating component
structure or when encountering schema validation errors.
> The bundled references/component-schema.md is a fallback snapshot. To refresh it
> after a Hyvä CMS update, regenerate it by reading the jsonschema/*.json files
> above — no helper script is required.
getEditorAttrs() on the root element and on each editable field element<script> tags in templates - use Alpine.js via alpine:init eventdefault_value key, NOT default - The correct JSON key for default values is default_value (with underscore), not default. Example: "default_value": "My Title" ✅, NOT "default": "My Title" ❌children is a root-level property, NOT a field type - Never use "type": "children" in content/design/advanced. Declare children at component root level. Access via $block->getData('children') in templates.attributes, NOT as direct properties - Use "attributes": {"required": true} ✅, NOT "required": true ❌. All HTML5 validation attributes (required, minlength, maxlength, pattern, min, max) must be inside the attributes object.<!-- Copyright © Hyvä Themes https://hyva.io. All rights reserved. Licensed under OSL 3.0 -->
Weekly roundup of top Claude Code skills, MCP servers, and AI coding tips.