How do I create a conditional download link with custom liquid metafields?

Hello!

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:

Download Lab Results PDF

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!

This is the code I used…

{% unless product.metafields.my_fields.sds_download.value.url == null %}
Download {{ product.title }} SDS
{% endunless %}

where does this code go?

Add a Block of type Custom Liquid and put the code in that block

Hi @IJ-SNP ,

For your issue, you can either add custom code or make it easier by installing the**Free Ease Product Attachments app :blush:** .

With this app, you can easily upload your downloadable PDF file, and then assign it to specific products/ collections or entire store.

(The Attachment/ File list)

Then, the file will only shown on the product pages that it is assigned to: