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 從公開儲存庫中收錄這些內容。

檢舉或申請下架