简体   繁体   中英

Shopify - Does Liquid Process Before JavaScript?

I'm trying to call shopify asset urls using javascript, dynamically concatenating a string into the liquid code, but it throws an error. I think that the Liquid must be processing before the JS.

function loadProductThumbnails(size) {
  $(".hammock-thumbnail1 img").attr("src", "{{ \'"+size+"-side-main-image.png' | asset_img_url: '150x150' }}");
}

Is this possible? I'm working with over a thousand images and had to type each liquid image url to generate separately. If I could do this dynamically, I cut the code down quite a bit. Thanks!

Liquid is rendered server side so you cannot integrate a JS var into your Liquid string.

You might make something like capturing part of your Liquid var with {% capture %} then use it in your function as var.

 function loadProductThumbnails(size) {
   $(".hammock-thumbnail1 img").attr("src", ""+size+"-side-main-image.png");
 }



 the `src` attribute maybe is not correct?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM