media
The media object can be returned by the product.media array or a
metafield.
You can use media filters to generate URLs and media displays. To learn about how to use media in your theme, refer to Support product media.
Note
Each media type has unique properties in addition to the general media properties. To learn about these
additional properties, refer to the reference for each type.
Properties
The media type.
Possible values image model video external_video ExampleFilter for media of a specific typeYou can use the
property with thewherefilter to filter theproduct.mediaarray for all media of a desired type.{% assign images = product.media | where: 'media_type', 'image' %}{% for image in images %}{{- image | image_url: width: 300 | image_tag }}{% endfor %}Code
{% assign images = product.media | where: 'media_type', 'image' %} {% for image in images %} {{- image | image_url: width: 300 | image_tag }} {% endfor %}Data
{ "product": { "media": [ "products/oil-dripping-into-jar.jpg" ] } }Output
<img src="//polinas-potent-potions.myshopify.com/cdn/shop/products/oil-dripping-into-jar.jpg?v=1650399519&width=300" alt="Viper venom" srcset="//polinas-potent-potions.myshopify.com/cdn/shop/products/oil-dripping-into-jar.jpg?v=1650399519&width=300 300w" width="300" height="200">The position of the media in the
product.mediaarray.If the source is a
metafield, thennilis returned.
{
"alt": "Dandelion milk",
"id": 21772527435841,
"media_type": "image",
"position": 1,
"preview_image": {}
}
Example
{
"alt": "Dandelion milk",
"id": 21772527435841,
"media_type": "image",
"position": 1,
"preview_image": {}
}Was this section helpful?