View PDF for several metaobjects by clicking button

Hello dear all,

I am currently working on create a button to display PDF of products, seems different product has several PDF,

I created several metaobjects in one metafield, in one of the metaobject field I can upload my PDF.

But the problem came when I created the button to view PDF, the button did not link to the PDF I upload, just opened a duplicate tab…

I tried few codes, but none of them worked.

Here are the codes I tried:

<a href="{{ product.metafields.custom.a1.my_pdf['metaobject_handle'].value.url }}" target="new" class="pdf-button">View PDF</a>
<a href="{{ product.metafields.custom.a1.my_pdf[metaobject_handle].value.url }}" target="new" class="pdf-button">View PDF</a>
<a href="{{ product.metafields.custom.a1.my_pdf.metaobject_handle.value.url }}" target="new" class="pdf-button">View PDF</a>
<a href="{{ shop.metaobjects.a1.my_pdf.metaobject_handle.value.url }}" target="new" class="pdf-button">View PDF</a>
<a href="{{ product.metafields.custom.a1['metaobject_handle'].value.url }}" target="new" class="pdf-button">View PDF</a>

I am looking forward to receiving some suggestions or brilliant ideas, thank you so much! :blush:

Hi @ruby5566

You have to use the link of the file to open the pdf to a different window. Do not use a metafield file. I tried using the file and the link of the file does not do it. Upload the file using Content > Files, copy the link provided and use the link for your metaobject.

Also, refer to code below on how to call the metaobject in the product.

{% for metaobject in shop.metaobjects.file.values %}
{{ metaobject.name }}
{% endfor %}

This is my metaobject settings

If it helps, likes and mark as solution is appreciated :blush:

Thank you for your kind reply, but at the end I figured it out by theme settings->customize, and I created a button, also choose the metafield which I can upload my files.

Hi @ruby5566 ,

I see that you’re looking to incorporate various PDF files into your products while encountering challenges in effectively organizing and presenting them on your storefront.

I’d recommend exploring the Free Easify Product Attachments App. This user-friendly application allows you to seamlessly upload your desired PDF files, associate them with relevant products, and ensure their accurate display on respective product pages :hugs: .

An advantageous aspect of this app is its simplicity; no coding required :+1: . You should give it a try!