Liquid, JavaScript, themes, sales channels
Hi.
I'm working on an app and been trying to insert a code into a theme file from my app.
I'm attempting to do something like this, but it doesn't work since JSDOM does not work properly with Liquid.
const productTemplateFile
= `
<div class="product-template__container page-width" id="ProductSection-{{ section.id }}" data-section-id="{{ section.id }}" data-section-type="product" data-enable-history-state="true" data-ajax-enabled="{{ settings.enable_ajax }}">
product page template file
</div>
`
const dom = new JSDOM(productTemplateFile);
const parent
= dom.window.document.querySelector(".product-template__container" );
const childElement = dom.window.document.createElement("div");
childElement.textContent = child
parent.appendChild(childElement)
const uri = `https://${shopOrigin}/admin/api/${API_VERSION}/themes/${themeId}/assets.json`;
const body = JSON.stringify({
asset: {
key: "sections/product-template.liquid",
value: dom.window.document.body.innerHTML
}
)
await fetch(uri, {
method: "PUT",
headers: { "X-Shopify-Access-Token": accessToken },
body
}
});
Is there a way to make JSDOM work with Liquid, or are there other ways to insert code into a theme using the Asset API?
Thanks.
Portrait of Stephen positioned next to an image of planet Earth, with the Stephen's World ...
By JasonH Mar 18, 2024Digital marketers and app developers have tracked activity in apps and websites for yea...
By Ollie Mar 13, 2024February was an exciting month with Shopify Editions, informative webinars, and more! F...
By JasonH Mar 7, 2024