use liquid var in js file

moyanoa
Excursionist
28 2 4

Hi there, is it possible to use liquid variables ina js file?

 

 html += '<div class="bc-sf-filter-product-item-wish"><button class="swym-button swym-add-to-wishlist-view-product product_{{product.id}}" data-swaction="addToWishlist" data-product-id="{{product.id | json}}"></button>x</div>';
 
thanks!!
0 Likes
pvoulg
Shopify Partner
171 26 45

Hi @moyanoa,

Yes, you can pass liquid variable in JS, either in a <script> tag (inside a snippet, for example), or by creating a .js.liquid file in your theme's assets.

Panos Voulgaris
Creative director / Partner @ MALVI
Founder @ function( )
0 Likes