URL: 1100 Series 50 Hour Service | Mahindra Direct Parts
Custom Liquid:
I would like the object data PDF URL to be a dynamic link to the page content, which would contain the URL for the required PDF
A user seeks to dynamically link a PDF URL within a custom Liquid template for a Shopify page. Currently, they have hardcoded the PDF URL in an <object> tag’s data attribute and want it to pull dynamically from page content.
Proposed Solution:
<object> tag’s data attributeid to the <object> element for JavaScript targetingdata attribute using setAttribute() methodImplementation approach:
data attribute in the <object> tagThe solution allows flexibility to generate URLs based on specific page content rather than maintaining static links in the template code.
URL: 1100 Series 50 Hour Service | Mahindra Direct Parts
Custom Liquid:
I would like the object data PDF URL to be a dynamic link to the page content, which would contain the URL for the required PDF
Hi there,
This is Jay from Fast Bunde. I hope you are doing well.
To make the tag’s data attribute dynamic and pull the PDF URL based on the page content, you can use a combination of JavaScript and HTML.
Here’s an approach you could use:
Here’s how the code could look:
<div style="text-align:center;">
<object id="dynamicPdf" width="900px" height="1850"></object>
</div>
<script>
// Example: Retrieve the PDF URL dynamically (you can replace this with your logic)
const pdfUrl = "https://cdn.shopify.com/s/files/1/0637/1187/1029/files/Mahindra_1100_Series_50_Hour_Service.pdf?v=17";
// Set the `data` attribute of the object dynamically
const pdfObject = document.getElementById("dynamicPdf");
pdfObject.setAttribute("data", pdfUrl);
</script>
If you want the PDF URL to be generated or fetched based on some specific content on the page, you can replace the pdfUrl assignment logic with something like fetching data from an API, reading from a meta tag, or parsing content dynamically.
Let me know if you need help customizing this further!