Solved

IF statement with metafields not working

emanuelepasin
Shopify Partner
6 1 3

Hi all,

I'm developing a custom block in OS 2.0 and inside the product-template.liquid file I'm using the 

 

{%- when 'optical_link' -%}

 

to show the block when it's selected from the theme editor.

Till here everything seems working fine, the link is visible and it works.

Now I need this section to appear only if the link is not blank so I've added the if statement as following

{%- when 'optical_link' -%}
  {%if product.metafileds.my_fields.optical_link != blank %}
     <div class="optical-link">
     <span>{{block.settings.optical_link_text}}</span>  
     <a href="{{block.settings.optical_url}}">Click Here</a> 
  </div>
{% endif %}

Unfortunately when I add the if statement nothing is showing up even if the metafield is not blank.

If I remove the if statement everything works fine.

Is there someone who could help me out?

Accepted Solution (1)
emanuelepasin
Shopify Partner
6 1 3

This is an accepted solution.

t was a typo in the copy paste, but thanks 🙏 

 

Anyway I've solved by using the .value 

product.metafields.my_fields.optical_link.value

View solution in original post

Replies 3 (3)

Jason
Shopify Expert
11190 225 2283

Did you copy and paste that code into this post?
There’s a typo - you have metfileds not metafields.

★ I jump on these forums in my free time to help and share some insights. Not looking to be hired, and not looking for work. http://freakdesign.com.au ★
emanuelepasin
Shopify Partner
6 1 3

This is an accepted solution.

t was a typo in the copy paste, but thanks 🙏 

 

Anyway I've solved by using the .value 

product.metafields.my_fields.optical_link.value
Sm3agal
New Member
6 0 0

Good day.

I have the same problem. I have checked everywhere and can't find any solution.

Below is my coding

For some reason it is just not returning any value after I have put this in.

      <div>
{% if product.metafields.myfields.building_manual_image != blank %}
          <p><span style="color: #77cd2c;"><b>Click on the below image to download the building instructions</b></span></p>
        <a href="{{product.metafields.my_fields.building_manual | file_url}}" target="_blank">
        <img src="{{product.metafields.my_fields.building_manual_image | image_url }}">
        {% endif %}
      </a>
      <br>
      <br>
      </div>