Downloadable pdf via metafields for some products

Topic summary

Goal: Add a collapsible row on product pages that shows a PDF download link stored in a product metafield, and hide the row when the metafield is empty.

Current issue: The collapsible row uses a Liquid field that always renders, so when the metafield is empty the row still appears with a non-functional link.

Proposed fix: Use a Liquid conditional to render the collapsible HTML only if the metafield has a value:

  • Check: {% if product.metafields.my_fields.download_pdf != blank %}
  • Place all collapsible row HTML and the link inside this condition to hide the row when no file exists.

Key concepts:

  • Metafields: Custom fields on products that can store data like a file URL.
  • Liquid: Shopify’s templating language used to conditionally render content.

Status and actions:

  • A code snippet demonstrating the conditional check was provided and is central to the solution.
  • No confirmation of implementation yet; helper offered step-by-step assistance.
  • Discussion remains open pending user testing and feedback.
Summarized with AI on December 28. AI used: gpt-5.

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

@DeeLT

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

           {% 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.