Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
I am unable to connect Dynamic sources to file metafields. Is there a workoaround to this? I only seem to be able connect Rich/Single line text.
This is the error I get once i code in the file reference metafield name:
{{ product.metafields.custom.product_installation_pdf }}
Any help?
Hey @Deanosaurus ,
You can't use a file directly as a metafield as of now. Files are only available in image pickers.
Here is the custom liquid to add pdf via metafields.
{% if product.metafields.custom.product_installation_pdf != blank %}
<a
href="{{ product.metafields.custom.product_installation_pdf | file_url }}"
style="text-decoration: underline;"
target="_blank"
>
Download Manual
</a>
{% endif %}
If you want the file to be downloaded instead of opening in a new tab, use the following.
{% if product.metafields.custom.product_installation_pdf != blank %}
<a
href="{{ product.metafields.custom.product_installation_pdf | file_url }}"
style="text-decoration: underline;"
target="_blank"
download
>
Download Manual
</a>
{% endif %}
♥ If you found my solution helpful, please consider giving it a Like and marking it as the ✔ Accepted Solution
Try our WhatsApp Chat Button Widget with multipe agents. Supachat: WhatsApp Chat Button
A Product of Maverick Studio
That's not entirely true - My shop has metafield with file, and it displays on my products as PDF. What I'm trying to replicate is the same / or have liquid code in those tabs.
As for the custom liquid code you just pasted, I got a better one, which basically makes the field empty unless you populate the metafield with the file.
{% unless product.metafields.custom.product_installation_pdf.value.url == null %}
<a target="_blank" href="{{ product.metafields.custom.product_installation_pdf
.value.url }}">Download Product Installation PDF</a>
{% endunless %}
Find Global Growth Opportunities For Your Business with Shopify AcademyLearn how to exp...
By Shopify Feb 4, 2025Hey Community, happy February! Looking back to January, we kicked off the year with 8....
By JasonH Feb 3, 2025Expand into selling wholesale with Shopify Academy’s learning path, B2B on Shopify: Lau...
By Shopify Jan 28, 2025