Liquid, JavaScript, themes, sales channels
Hello, experts.
I assigned global variables on settings_schema.json like it.
Solved! Go to the solution
This is an accepted solution.
@BrightPearl
There are two potential solutions for that:
1. Add the settings elements to a data attribute from any .liquid file. For example, you could create an empty div within the theme.liquid:
<div id=customSettings" data-test="{{ settings.global_shipping_start_cost }}"></div>
And then, from theme.js:
const $settings = document.querySelector(`#customSettings`);
const test = $settings.getAttribute("data-test");
alert(test);
2. From within a .js.liquid file.
You would need to rename your theme.js file to theme.liquid.js. Here is how it would look like:
const test= `{{ settings.global_shipping_start_cost }}`.trim();
alert(test);
Kind regards,
Diego
This is an accepted solution.
@BrightPearl
There are two potential solutions for that:
1. Add the settings elements to a data attribute from any .liquid file. For example, you could create an empty div within the theme.liquid:
<div id=customSettings" data-test="{{ settings.global_shipping_start_cost }}"></div>
And then, from theme.js:
const $settings = document.querySelector(`#customSettings`);
const test = $settings.getAttribute("data-test");
alert(test);
2. From within a .js.liquid file.
You would need to rename your theme.js file to theme.liquid.js. Here is how it would look like:
const test= `{{ settings.global_shipping_start_cost }}`.trim();
alert(test);
Kind regards,
Diego
Thank you, Diego!
You're welcome!
@diego_ezfy Thanks for your reply.
Next Monday, I will apply your solution, then I will accept your solution as a solution.
Many thanks!
User | RANK |
---|---|
33 | |
27 | |
17 | |
9 | |
9 |
We're excited to announce improvements to the threaded messaging experience in our communi...
By TyW May 31, 2023Thank you to everyone who participated in our AMA with Klaviyo. It was great to see so man...
By Jacqui May 30, 2023Photo by Marco Verch Sales channels on Shopify are various platforms where you can sell...
By Ollie May 25, 2023