Media filters return URLs and tags for the media of a product.

URLs of videos and 3D models hosted by VersaCommerce may be signed, which means they expire and change. Do not cache URLs of hosted videos and 3D models.

externalvideotag

Creates an iframe that contains a Vimeo or YouTube video player.

If alt text is set for the video, it appears in the title attribute of the iframe. Without alt text, the product title appears in the title attribute.

{% if product.featured_media.media_type == "external_video" %}
  {{ product.featured_media | external_video_tag }}
{% endif %}
<iframe frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen src="https://www.youtube.com/embed/neFK-pv2sKY?controls=1&enablejsapi=1&modestbranding=1&playsinline=1&rel=0">...</iframe>
<iframe frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen src="https://player.vimeo.com/video/506225278?byline=0&controls=1&playsinline=1&title=0" title="Alt Text Here"></iframe>

You can pass HTML attributes as options to add them to the iframe:

{% if product.featured_media.media_type == "external_video" %}
  {{ product.featured_media | external_video_tag: class: "youtube_video" }}
{% endif %}
<iframe frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen class="youtube_video" src="https://www.youtube.com/embed/neFK-pv2sKY?controls=1&enablejsapi=1&modestbranding=1&playsinline=1&rel=0">...</iframe>

externalvideourl

Sets parameters for the external video player created by external_video_tag. You can pass the player parameters that YouTube and Vimeo support.

This example changes the color of the YouTube player:

{% if product.featured_media.media_type == "external_video" %}
  {{ product.featured_media | external_video_url: color: "white" |  external_video_tag }}
{% endif %}
<iframe frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen src="https://www.youtube.com/embed/neFK-pv2sKY?color=white&controls=1&enablejsapi=1&modestbranding=1&playsinline=1&rel=0">
  ...
</iframe>

This example mutes a Vimeo video and plays it in a loop:

{% if product.featured_media.media_type == "external_video" %}
  {{ product.featured_media | external_video_url: loop: "1", muted: "1" |  external_video_tag }}
{% endif %}
<iframe frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen src="https://player.vimeo.com/video/506225278?byline=0&controls=1&playsinline=1&title=0&loop=1&muted=1" title="Alt Text Here"></iframe>

image_url

Used with a media object, image_url creates a URL for the preview image of the media. Combine image_url with image_tag to show the preview image on a page.

image_url requires a width or height attribute. Learn more about size parameters.

{% if product.featured_media.media_type == "video" %}
  {{ product.featured_media | image_url: width: 500, height: 500, format: "jpg" }}
{% endif %}
//cdn.versacommerce.de/s/files/1/1425/8696/products/b15ddb43cbac45b1ae2685223fa3536d.jpg?v=1560284062&width=500&height=500

Used with an image object, image_url returns the URL of the image. Combine image_url with image_tag to show the image on a page.

{% if product.featured_media.media_type == "image" %}
  {{ product.featured_media | image_url: width: 500, height: 500 }}
{% endif %}
https://cdn.versacommerce.de/s/files/1/1183/1048/products/boat-shoes.jpeg?v=1459175177&width=500&height=500

media_tag

Creates the matching tag for the media:

{% if product.featured_media.media_type == "model" %}
  {{ product.featured_media | media_tag }}
{% endif %}
 <model-viewer src="https://cdn.example.com/models/stroller.glb" ios-src="https://cdn.example.com/models/stroller.usdz" poster="//cdn.versacommerce.de/s/files/1/1425/8696/products/placeholder_image_small.jpg?v=1560284071" camera-controls="true">

  ...

 </model-viewer>

You can change the size of the poster image of the media tag with the image_size option:

{% if product.featured_media.media_type == "model" %}
  {{ product.featured_media | media_tag: image_size: "1024x" }}
{% endif %}
 <model-viewer src="https://cdn.example.com/models/stroller.glb" ios-src="https://cdn.example.com/models/stroller.usdz" camera-controls="true" poster="//cdn.versacommerce.de/s/files/1/1425/8696/products/placeholder_image_1024x.jpg?v=1560875434"></model-viewer>

modelviewertag

Note: product.media currently contains no 3D models in VersaCommerce. The filter creates a <model-viewer> element when it receives an object with usable sources.

Creates a Google Model Viewer component tag for the given 3D model:

{% if product.featured_media.media_type == "model" %}
  {{ product.featured_media | model_viewer_tag }}
{% endif %}
 <model-viewer src="https://cdn.example.com/models/stroller.glb" ios-src="https://cdn.example.com/models/stroller.usdz" poster="//cdn.versacommerce.de/s/files/1/1425/8696/products/placeholder_image_small.jpg?v=1560284071" camera-controls="true">

  ...

 </model-viewer>

You can set attributes of the model viewer component by adding options to the filter. By default the alt attribute is set to the alt text of the media, the poster attribute to the preview image of the media, and camera-controls is enabled.

This example sets a new background color for the model viewer component:

{% if product.featured_media.media_type == "model" %}
  {{ product.featured_media | model_viewer_tag: background-color: "#455A64" }}
{% endif %}
 <model-viewer background-color="#455A64" src="https://cdn.example.com/models/stroller.glb" ios-src="https://cdn.example.com/models/stroller.usdz" poster="//cdn.versacommerce.de/s/files/1/1425/8696/products/placeholder_image_small.jpg?v=1560284071" camera-controls="true">

  ...

 </model-viewer>

You can change the size of the poster image of the model viewer with the image_size option:

{% if product.featured_media.media_type == "model" %}
  {{ product.featured_media | model_viewer_tag: image_size: "1024x" }}
{% endif %}
 <model-viewer src="https://cdn.example.com/models/stroller.glb" ios-src="https://cdn.example.com/models/stroller.usdz" camera-controls="true" ar="true" poster="//cdn.versacommerce.de/s/files/1/1425/8696/products/placeholder_image_1024x.jpg?v=1560875434"></model-viewer>

video_tag

Creates a video tag:

{% if product.featured_media.media_type == "video" %}
  {{ product.featured_media | video_tag }}
{% endif %}
 <video playsinline="true" controls="">

  <source src="https://cdn.example.com/videos/master.m3u8" type="application/x-mpegURL">

  <source src="https://cdn.example.com/videos/SD-360p.mp4" type="video/mp4">

  <source src="https://cdn.example.com/videos/SD-480p.mp4" type="video/mp4">

  <source src="https://cdn.example.com/videos/HD-720p.mp4" type="video/mp4">
  <p>Sorry html5 video is not supported in this browser</p>

 </video>

Use the image_size option to change the size of the video's poster image:

{% if product.featured_media.media_type == "video" %}
  {{ product.featured_media | video_tag: image_size: "1024x" }}
{% endif %}
 <video playsinline="true" poster="//cdn.versacommerce.de/s/files/1/1425/8696/products/dc6b2518bec04c42a7a5239f563d8cb4_1024x.jpg?v=1560875163">

  <source src="https://cdn.example.com/videos/master.m3u8" type="application/x-mpegURL">

  <source src="https://cdn.example.com/videos/HD-720p.mp4" type="video/mp4">

  <source src="https://cdn.example.com/videos/SD-480p.mp4" type="video/mp4">

  <img src="//cdn.versacommerce.de/s/files/1/1425/8696/products/dc6b2518bec04c42a7a5239f563d8cb4_1024x.jpg?v=1560875163">

 </video>