Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Hi,
I am wanting to add a video to my product page template but I want the video to disappear when blank - I tried doing this through custom liquid but not sure how I can make the two pieces of code to work.... I'm a novice when it comes to coding.
{%- if product.metafields.custom.product_video != blank -%}
{%- endif -%}
<video width="full-width" controls="controls" poster="{{product.metafields.custom.product_video_thumbnail_image}}">
</video>
Solved! Go to the solution
This is an accepted solution.
Try one of these two please:
{%- if product.metafields.custom.product_video == true -%}
<video width="full-width" controls="controls" poster="{{product.metafields.custom.product_video_thumbnail_image}}">
<source src="{{product.metafields.custom.product_video}}" type="video/mp4">
</video>
{%- endif -%}
or
{%- if product.metafields.custom.product_video != blank -%}
<video width="full-width" controls="controls" poster="{{product.metafields.custom.product_video_thumbnail_image}}">
<source src="{{product.metafields.custom.product_video}}" type="video/mp4">
</video>
{%- endif -%}
Hi @Orlando22
{%- if product.metafields.custom.product_video != "" -%}
<video width="full-width" controls="controls" poster="{{product.metafields.custom.product_video_thumbnail_image}}">
<source src="{{product.metafields.custom.product_video}}" type="video/mp4">
</video>
{%- endif -%}
This will show the video only if the field is not blank. Is this what you want?
Hi, thanks so much for your response
- Yes, we want the whole video section to be hidden if this metafield in the custom liquid is blank. Since some of our products have videos and some don't
I gave this a try but it still shows the video player function, if a product doesn't have that metafield filled
Can you share the link for this page?
This link is a page that doesn't have the metafield filled
https://amonev.com/products/kids-nursery-lampshade-lion
This is a page which does have the metafield value filled
https://amonev.com/collections/sensory-tent/products/autism-pop-up-sensory-tent-blackout-dark-den
This is an accepted solution.
Try one of these two please:
{%- if product.metafields.custom.product_video == true -%}
<video width="full-width" controls="controls" poster="{{product.metafields.custom.product_video_thumbnail_image}}">
<source src="{{product.metafields.custom.product_video}}" type="video/mp4">
</video>
{%- endif -%}
or
{%- if product.metafields.custom.product_video != blank -%}
<video width="full-width" controls="controls" poster="{{product.metafields.custom.product_video_thumbnail_image}}">
<source src="{{product.metafields.custom.product_video}}" type="video/mp4">
</video>
{%- endif -%}
Thank you so much or your help.... this worked perfectly
Which of the two worked?
Sorry, I only just saw this - the second one worked which says blank
I am trying to do the same thing, but with a metafield within a metaobject, but I have a hard time to reference that metafield. Do you know what the format should be please?
By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024Thanks to everyone who participated in our AMA with 2H Media: Marketing Your Shopify St...
By Jacqui Sep 6, 2024