IF statement with metafields not working

Solved
emanuelepasin
Tourist
4 1 2

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?

0 Likes
Jason
Shopify Expert
10414 164 2059

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

I jump on these forums to help and share some insights. Not looking to be hired, and not looking for work.

Don't hand out staff invites or give admin password to forum members unless absolutely needed. In most cases the help you need can be handled without that.


★ http://freakdesign.com.au ★
0 Likes
emanuelepasin
Tourist
4 1 2

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
0 Likes
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>
0 Likes