home / skills / hyva-themes / hyva-ai-tools / hyva-render-media-image
This skill generates responsive picture elements for Hyva templates using the Media view model to optimize images and improve LCP.
npx playbooks add skill hyva-themes/hyva-ai-tools --skill hyva-render-media-imageReview the files below or copy the command above to add this skill to your agents.
---
name: hyva-render-media-image
description: 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".
---
# 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:**
| Scenario | Pattern to Use |
|----------|---------------|
| Single image, literal values | Single Image Example |
| Single image from variable | Wrap in array: `[$imageData]` |
| Multiple images from variable | Pass directly: `$images` |
| Different images for mobile/desktop | Responsive Images with Media Queries |
| Need to style the `<picture>` wrapper | Picture 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 Type | Attributes |
|------------|------------|
| 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 -->
This skill generates responsive <picture> elements for Hyvä Theme templates using the Hyvä Media view model. It creates accessible, performance-minded image markup for hero banners, product images, and any image that needs responsive breakpoints. Use it to produce HTML that improves Core Web Vitals and supports lazy/eager loading strategies.
The skill asks for either direct image values or a PHP variable containing image configuration and then emits the PHP snippet that calls \Hyva\Theme\ViewModel\Media::getResponsivePictureHtml. It maps image configs to <picture> sources, sets <img> attributes (alt, loading, fetchpriority) and optionally adds attributes to the <picture> wrapper. The output is ready to paste into a Hyvä PHTML template and follows responsive and accessibility best practices.
What input formats are accepted for image data?
Either direct literal values (paths, dimensions, alt) or a PHP variable containing the required image config array. Follow the documented image configuration format for keys and structure.
How do I decide eager vs lazy loading?
Use eager and fetchpriority=high for the hero/LCP image that appears above the fold. Use lazy for images that are below the fold to save bandwidth and improve initial load.