Re: How to make a section disappear if it's metafield is blank?

Solved

How to make a section disappear if it's metafield is blank?

Orlando22
Tourist
16 0 1

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 -%}

Display: none

{%- endif -%}
<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>

 

Accepted Solution (1)
Lucid_Polygon
Shopify Partner
349 63 92

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 -%}
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Click Accept as Solution

View solution in original post

Replies 10 (10)

Lucid_Polygon
Shopify Partner
349 63 92

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?

- Was my reply helpful? Click Like to let me know!
- Was your question answered? Click Accept as Solution
Orlando22
Tourist
16 0 1

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

 

Orlando22
Tourist
16 0 1

I gave this a try but it still shows the video player function, if a product doesn't have that metafield filled

Example.png

Lucid_Polygon
Shopify Partner
349 63 92

Can you share the link for this page?

- Was my reply helpful? Click Like to let me know!
- Was your question answered? Click Accept as Solution
Orlando22
Tourist
16 0 1

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


Lucid_Polygon
Shopify Partner
349 63 92

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 -%}
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Click Accept as Solution
Orlando22
Tourist
16 0 1

Thank you so much or your help.... this worked perfectly

Lucid_Polygon
Shopify Partner
349 63 92

Which of the two worked?

- Was my reply helpful? Click Like to let me know!
- Was your question answered? Click Accept as Solution
Orlando22
Tourist
16 0 1

Sorry, I only just saw this - the second one worked which says blank

alexk91
Shopify Partner
1 0 0

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?