How to add Shopify liquid into Javascript?

Hi all, I am creating a javascript price calculator that works perfectly so for, however I need it to work dynamically across all products rather than just using the static values I had to the Javascript code. I will add my code below, if anyone can point me in the right direction of adding Shopify liquid variables to Javascript I would really appreciate it.


Thanks in advance!

Hi @adammahon

It can be easier if you can describe background of the function you want to make.

But there are some ways you can try

  • Move that script to a .liquid file (I assumed it’s on product page) then you can use {{ liquid code}} inside the script tag

  • If you check on the default theme like Debut theme, there is a file in the name theme.js.liquid
    It still a js file but can use the liquid code inside of it

  • In the liquid file, render your data to HTML in a kind like


    then on the script file you can achieve that data via javascript.

1 Like

Thank you for your reply. This worked!

1 Like