File URL not generating

Hi!

I am trying to add a PDF file to my products which will contain special instructions for that product. I used metafield to store the information and set the type as file.

I do not want to edit the code directly instead I used custom liquid block on Dawn theme where I can add my additonal code for the PDF.

I used the code:

Do not forget to check the Washing instructions for the product.

but its not generating the URL for the file instead generating some weird URL: gid://shopify/GenericFile/29950164336807

I also found this documenation where it suggested me use .value after the key to show value but this is also not working. Doc: https://shopify.dev/docs/api/liquid/objects/metafield#metafield-access-metafields

Please help

Hi @CraftTech ,

I see what you’re trying to implement here, and it’s great that you’re using the custom liquid block rather than editing the theme’s source code directly.

The code you shared is almost correct, but to generate the file URL, you’ll need to add a liquid filter. Please use the code below to properly generate the URL for the uploaded file:

Do not forget to check the Washing instructions for the product.

I hope this helps!

If my response helped you, please consider giving it a like ( :+1: ) and marking it as an accepted solution if it resolved your issue. Your feedback helps other community members with similar questions.

Thank you!

Regards,
Abhishek from Swym

Thanks @swym

This solved my problem :heart_eyes:

Hey @swym , I encountered another bug where this code displays for all products. Instead what I would prefer is that it should be only shown on products with PDF file.

Can u please help me with this.

Hi @CraftTech ,

You can fix that by replacing the code I shared earlier with the code below:

{% if product.metafields.custom.washing_manual != blank %}
Do not forget to check the Washing instructions for the product.
{% endif %}

This code first checks if the product has values saved in the metafield before rendering the content directly.

I hope this helps!

Regards,

Abhishek from Swym

Thanks mate! You are best

Hi,

I am trying to make something similar but with an audio player embed. If I write the code in the product description itself, it works. But if I try to do it on the theme editor, or code, by adding a reference to the metafield… it doesn’t allow me to save.
Any tips?

This is the code I had on the description: