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 the
where
filter to filter theproduct.media
array 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 %}{% assign images = product.media | where: 'media_type', 'image' %} {% for image in images %} {{- image | image_url: width: 300 | image_tag }} {% endfor %}
{ "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.media
array.If the source is a
metafield, then
nil
is returned.
{
"alt": "Dandelion milk",
"id": 21772527435841,
"media_type": "image",
"position": 1,
"preview_image": {}
}
{
"alt": "Dandelion milk",
"id": 21772527435841,
"media_type": "image",
"position": 1,
"preview_image": {}
}
Was this section helpful?