Using mathematical liquid variable in javascript

318 Views Asked by At

I am trying to get a Shopify liquid variable available for use in a javascript:

{% assign gtfs = 39900 | minus: cart.total_price | money %}

Further down in the javascript:

var feedback = '<div class="added-to-cart" id="ajaxify"><p class="ajaxified-cart-feedback ' + success + '">' + html + {{ gtfs | json }} + '</p></div>';

But for some reason it always returns 399,00. It is like it won't accept the math done in the top part when assigning gtfs.

I tried inserting cart.total_price instead in the script (just to check if the variable was present) - which returns the cart value as intended.

But I need to deduct the cart value from 399 and show that amount (to show how much up to free shipping) - e.g. "You are only 172 DKK away from free shipping".

1

There are 1 best solutions below

0
On

I think I got it myself. The liquid variable is loaded in the DOM - hence not updated upon add-to-basket, so I will have to look for event listeners.

Thanks.