Hyva Render Media Image

hyva-themes/hyva-ai-tools/skills/hyva-render-media-image

作者 hyva-themesa28a3333bcfae05dcba07e88f38a5ff9579903c7无许可证收录于 2026年10月9日更新于 2026年10月9日

Generate responsive image code for Hyvä Theme templates using the Media view model. This skill should be used when the user wants to render images in a Hyvä template, create responsive picture elements, add hero images, product images, or any image that needs responsive breakpoints. Trigger phrases include "render image", "add image to template", "responsive image", "picture element", "hero image", "responsive banner", "image for mobile and desktop", or "banner image".

AI 生成的概览

使用 Media 视图模型为 Hyvä 主题模板生成响应式图片代码。

功能
该技能使用 Hyva\Theme\ViewModel\Media 视图模型,为 Hyvä 主题的 PHTML 模板生成响应式 picture 元素代码。它会先收集图片路径、尺寸、替代文本和加载需求,然后输出 getResponsivePictureHtml 等 PHP 代码片段。它还说明首屏主图与折叠下方图片的加载策略,并指向参考文件获取完整 API。
适用场景
适用于向 Hyvä PHTML 模板添加图片、构建移动端与桌面端使用不同来源的响应式图片,以及实现主图横幅、商品图片和 CMS 内容图片。也适合处理 LCP、CLS 等 Core Web Vitals 相关优化。
运行要求
需要具备 Hyva\Theme\ViewModel\Media 视图模型的 Hyvä 主题 Magento 项目。不附带脚本,仅为说明文档,并依赖随附的参考文件。

Hyvä Render Image

Generate responsive <picture> elements for Hyvä Theme templates using the \Hyva\Theme\ViewModel\Media view model.

When to Use

  • Adding images to Hyvä PHTML templates
  • Creating responsive images with different sources for mobile/desktop
  • Implementing hero banners, product images, or CMS content images
  • Optimizing images for Core Web Vitals (LCP, CLS)

Workflow

1. Gather Image Requirements

The user may provide image data in one of these ways:

Option A: Direct values - Ask the user for:

  1. Image path(s) - Location in pub/media/ (e.g., wysiwyg/hero.jpg, catalog/product/...)
  2. Image dimensions - Width and height in pixels
  3. Responsive requirements - Different images for mobile vs desktop?
  4. Image purpose - Hero/LCP image (eager loading) or below-fold (lazy loading)?
  5. Alt text - Meaningful description for accessibility

Option B: PHP variable - The user provides a variable name (e.g., $imageData, $heroImage). Inform the user of the required array structure documented in references/rendering-images.md under ## Image Configuration Format.

2. Generate the Code

Refer to references/rendering-images.md for the complete API reference, code examples, and all configuration options.

Choose the appropriate pattern:

ScenarioPattern to Use
Single image, literal valuesSingle Image Example
Single image from variableWrap in array: [$imageData]
Multiple images from variablePass directly: $images
Different images for mobile/desktopResponsive Images with Media Queries
Need to style the <picture> wrapperPicture Element Attributes

Base template:

php
<?php/** @var \Hyva\Theme\ViewModel\Media $mediaViewModel */$mediaViewModel = $viewModels->require(\Hyva\Theme\ViewModel\Media::class);
echo $mediaViewModel->getResponsivePictureHtml(    $images,        // Array of image configs (see reference for format)    $imgAttributes, // Optional: alt, class, loading, fetchpriority    $pictureAttributes // Optional: class, data-* attributes for <picture>);

3. Set Loading Strategy

Image TypeAttributes
Hero/LCP (above fold)'loading' => 'eager', 'fetchpriority' => 'high'
Below fold'loading' => 'lazy'

Resources

  • references/rendering-images.md - Complete API reference with method signature, all configuration options, code examples, and best practices
<!-- Copyright © Hyvä Themes https://hyva.io. All rights reserved. Licensed under OSL 3.0 -->

来源与署名

来源:hyva-themes/hyva-ai-tools位于skills/hyva-render-media-image提交a28a333

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架