All things Shopify and commerce
I am trying to add a variant metafield that displays a pdf image with a url link to the relevant cds file, i have got the product ones working but not getting anything for the variant, please be gentle i am not a coder, just trying to work my way through this issue (code is in a custom liquid file and is referenced in theme product page)
{% for item in product.metafields.custom.technical_datasheet.value -%}
{%- if item != blank -%}
<div class= "pdf-child">
<a href={{ item }} target="_blank" rel="noopener noreferrer"><img src="https://cdn.shopify.com/s/files/1/0606/5150/3668/files/images.png?v=1661969450" alt="PDF Document" width="60"></a>
</br><strong>Technical Datasheet</strong>
</br></div>
{%- endif -%}
{%- endfor %}
{% for item in variant.metafields.custom.technical_data.value -%}
{%- if item != blank -%}
<div class= "pdf-child">
<a href={{ item }} target="_blank" rel="noopener noreferrer"><img src="https://cdn.shopify.com/s/files/1/0606/5150/3668/files/images.png?v=1661969450" alt="PDF Document" width="60"></a>
</br><strong>Model Data</strong>
</br></div>
{%- endif -%}
{%- endfor %}
Hi @Inscale
You have to loop through the variants
Check below code
{% for variant in product.variants %}
{% for item in variant.metafields.custom.technical_data.value -%}
{%- if item != blank -%}
<div class= "pdf-child">
<a href={{ item }} target="_blank" rel="noopener noreferrer"><img src="https://cdn.shopify.com/s/files/1/0606/5150/3668/files/images.png?v=1661969450" alt="PDF Document" width="60"></a>
</br><strong>Model Data</strong>
</br></div>
{%- endif -%}
{%- endfor -%}
{%- endfor -%}
Thank you Rishihuptech, unfortunately that did not work, so i am probably missing something else, probably somewhere else to. But thank you for reply, very kind
Hi @Inscale ,
Just to remind code you are using is for reading variant metafield of metaobject type.
{% for item in product.metafields.custom.technical_datasheet.value -%}
.value we use for metaobject.
for metafield please use below one code
{% for variant in product.variants %}
{{ variant.metafields.custom.technical_datasheet | file_url }}
{% endfor %}
file_url filter used for file type metafield.
Hope this will helps...
Thank you for the detail. The code used (with .value) was written before metaobjects was available and it works for the 'product' links, what i am trying to add is a url for the variant, sounds more and more complicated as i type it, but file_url just returns 3 text lines ending in ?498 which I'm guessing is an error code. As i say I'm no coder I'm just trying to logically work my way through the problem, but thank you for the detail does seam to get me a step closer if not the answer, appreciated
best would be to share a video how you have created metafield at variant and how this info you want on the page.
Not really done videos before, i leave that to Marketing dept., but please let me give some more detail which may help
So we have a product called a CP P4 and CP Y4 (just using these to sort issue)
CP P4 has 3 pdf url's listed on page currently Data sheet, Manual and Technical Datasheet - Data Sheet is the model detail and shows available variants, manual is basically instructions, but technical data sheet is related to the variant, so each variant has its own technical data sheet (variant is what we call model on the pages)
Obviously i can list them all with product.metafield, but would need to rename each one for every product and the number of variants can be much larger than these examples, so ideally a different technical datasheet is added when a guest selects a different model on the product page
Yes i can list each variant as a single product and avoid this as i can list the individual datasheets on each page, but that then means a huge collection page and not that user friendly maybe
The links are listed via a custom liquid file shown in theme edit here
Metafields
and the code so far
{% comment %} Manuals and data sheets links to sites pulling from product metafeilds only shows if info is there Can show multiple items with the for loop. {% endcomment %}
{% for item in product.metafields.custom.data_sheets.value -%}
{%- if item != blank -%}
<div class= "pdf-child">
<a href={{ item }} target="_blank" rel="noopener noreferrer"><img src="https://cdn.shopify.com/s/files/1/0606/5150/3668/files/images.png?v=1661969450" alt="PDF Document" width="60"></a>
</br><strong>Data Sheet</strong>
</br></div>
{%- endif -%}
{%- endfor %}
{% for item in product.metafields.custom.manuals.value -%}
{%- if item != blank -%}
<div class= "pdf-child">
<a href={{ item }} target="_blank" rel="noopener noreferrer"><img src="https://cdn.shopify.com/s/files/1/0606/5150/3668/files/images.png?v=1661969450" alt="PDF Document" width="60"></a>
</br><strong>Manual</strong>
</br></div>
{%- endif -%}
{%- endfor %}
{% for item in product.metafields.custom.technical_datasheet.value -%}
{%- if item != blank -%}
<div class= "pdf-child">
<a href={{ item }} target="_blank" rel="noopener noreferrer"><img src="https://cdn.shopify.com/s/files/1/0606/5150/3668/files/images.png?v=1661969450" alt="PDF Document" width="60"></a>
</br><strong>Technical Datasheet</strong>
</br></div>
{%- endif -%}
{%- endfor %}
{% for variant in product.variants %}
{{ variant.metafields.custom.technical_datasheet.value }}
{%- if item != blank -%}
<div class= "pdf-child">
<a href={{ item }} target="_blank" rel="noopener noreferrer"><img src="https://cdn.shopify.com/s/files/1/0606/5150/3668/files/images.png?v=1661969450" alt="PDF Document" width="60"></a>
</br><strong>Model Data</strong>
</br></div>
{%- endif -%}
{%- endfor -%}
Sorry its a bit long winded and maybe confusing, but not sure how else to detail it
Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025