Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
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!
By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024Thanks to everyone who participated in our AMA with 2H Media: Marketing Your Shopify St...
By Jacqui Sep 6, 2024