FROM CACHE - en_header

Custom Liquid Metafield Downloadable PDF

New Member
3 0 1


I am new to metafields and custom liquid and I am trying to create a link to a downloadable PDF that would go to each product.

The code I have right now is this:


<a href="{% if product.metafields.my_fields.lab_results_pdf_file != blank %}
  {{ product.metafields.my_fields.lab_results_pdf_file.value.url }}
{% endif %}">Download Lab Results PDF</a>



What I want the code to say is, IF there is a file in the metafield THEN show the text for the download link. ELSE show nothing. And when there is a file available, then if you click the link it will download the file.

Thank you very much in advance! 


Reply 1 (1)
New Member
2 0 0

This is the code I used...

{% unless product.metafields.my_fields.sds_download.value.url == null %}
<a target="_blank" href="{{ product.metafields.my_fields.sds_download.value.url }}">Download {{ product.title }} SDS</a>
{% endunless %}