external_ video_ tag
variable | external_video_tag
returns string
Generates an HTML <iframe>
tag containing the player for a given external video. The input for the
filter can be either a
media
object or .
If alt text is set on the video, then it's
included in the title
attribute of the <iframe>
. If no alt text is set, then the title
attribute is set to the
product title.
{% for media in product.media %}
{% if media.media_type == 'external_video' %}
{% if media.host == 'youtube' %}
{{ media | external_video_url: color: 'white' | external_video_tag }}
{% elsif media.host == 'vimeo' %}
{{ media | external_video_url: loop: '1', muted: '1' | external_video_tag }}
{% endif %}
{% endif %}
{% endfor %}
{% for media in product.media %}
{% if media.media_type == 'external_video' %}
{% if media.host == 'youtube' %}
{{ media | external_video_url: color: 'white' | external_video_tag }}
{% elsif media.host == 'vimeo' %}
{{ media | external_video_url: loop: '1', muted: '1' | external_video_tag }}
{% endif %}
{% endif %}
{% endfor %}
{
"product": {
"media": [
{
"host": "youtube",
"media_type": "external_video"
},
{
"host": null,
"media_type": "video"
}
]
}
}
Output
<iframe frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="allowfullscreen" src="https://www.youtube.com/embed/vj01PAffOac?color=white&controls=1&enablejsapi=1&modestbranding=1&origin=https%3A%2F%2Fpolinas-potent-potions.myshopify.com&playsinline=1&rel=0" title="Potion beats"></iframe>
Anchor to HTML attributes
HTML attributes
variable | external_video_tag: attribute: string
You can specify HTML attributes by adding a parameter that matches the attribute name, and the desired value.
{% for media in product.media %}
{% if media.media_type == 'external_video' %}
{% if media.host == 'youtube' %}
{{ media | external_video_url: color: 'white' | external_video_tag: class:'youtube-video' }}
{% endif %}
{% endif %}
{% endfor %}
{% for media in product.media %}
{% if media.media_type == 'external_video' %}
{% if media.host == 'youtube' %}
{{ media | external_video_url: color: 'white' | external_video_tag: class:'youtube-video' }}
{% endif %}
{% endif %}
{% endfor %}
{
"product": {
"media": [
{
"host": "youtube",
"media_type": "external_video"
},
{
"host": null,
"media_type": "video"
}
]
}
}
Output
<iframe frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="allowfullscreen" class="youtube-video" src="https://www.youtube.com/embed/vj01PAffOac?color=white&controls=1&enablejsapi=1&modestbranding=1&origin=https%3A%2F%2Fpolinas-potent-potions.myshopify.com&playsinline=1&rel=0" title="Potion beats"></iframe>
Was this page helpful?