Downloadable pdf via metafields for some products

DeeLT
Excursionist
17 0 4

I want to add a collapsible row to my product template, then fill that with a link to download a pdf that is assigned to the product via metafields.  I also want to hide any empty collapsible rows that are empty.

 

I added a liquid field to the collapsible row, and then added code in there to add the download link via the metafield.  The problem is the metafield is empty and the liquid field is not, so the collapsible row is never empty.  It just has a link that doesn't go anywhere if the metafield is empty.

 

What would be the easiest way to have the link go to the file in the metafield but hide it if there is no file in the metafield?

 

This is an example of a product that has a growing guide. https://8c4caf-34.myshopify.com/products/lettuce-bibb

 

This product does not have a growing guide. https://8c4caf-34.myshopify.com/products/vegetables-romanesco-puntoverde

Reply 1 (1)

Liqiud_xPert_SJ
Shopify Partner
978 117 151

@DeeLT 

 

{% if product.metafields.my_fields.download_pdf != blank %}
////your html code start like any div tag <div>
{{ if product.metafields.my_fields.download_pdf }}
////your html code end like any div tag close </div>
           {% endif %}

you need to add a check for your metafield. If the metafield empty then you html or collapse content will be not visible like below example code.

 

 

Do let me know if you want me to help you in this step by step.

- If you need any technical assistance, feel free to send me a DM. You no longer have to search for answers without getting a response.
- Please don't forget to Like and Mark Solution to the post that helped you. Thanks!
- Your Shopify Solution Specialist For further discussion contact: Email ID- Liqud_3xPert_SJ OR Whatsapp
- Buy a Coffee for me to get more frequently help 🙂
- Hire Me to unlock the full potential of your e-commerce store Now 🙂- If you need any technical assistance, feel free to send me a DM. You no longer have to search for answers without getting a response.
- Please don't forget to Like and Mark Solution to the post that helped you. Thanks!
- Your Shopify Solution Specialist For further discussion contact: Email ID- Liqud_3xPert_SJ OR Whatsapp
- Buy a Coffee for me to get more frequently help 🙂
- Hire Me to unlock the full potential of your e-commerce store Now 🙂