Liquid Variables in Java Script

New Member
9 0 0

Is it possibel to use the Liquid variables in java script to set the values?

some thing like this

{% assign count = 0 %}

< input = button" onclick =" setCount()")
{if count > 1} { do something


< script type=javascript>
{ count = 5



thanks for the help

Shopify Expert
3937 16 325


I have no idea what you're trying, but the easy answer is yes. All my custom hacks involve this pattern. Inside a Liquid loop, say for product in products I then dump a little javascript that copies all the item properties to an array. This allows me to add client-side behaviours using data from Liquid. You can make up tons of little ditties with this pattern. It is one way to make Shopify sites with pizazz. Of course, limiting yourself to Liquid is safer, but it has it's obvious limits, hence the existence of the Javascript API. Good luck with your scripting...

Custom Shopify Apps built just for you!