本文介绍了在.js.liquid文件中使用asset_url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编码Shopify主题,我需要在其中一个模板中使用带有自定义指针的Google Maps.

I'm coding a Shopify theme and I need to use Google Maps with custom pointers in one of my templates.

在Javascript文件中使用asset_url时遇到麻烦,因此我可以正确链接到新的指针/标记图形.关于我在做什么的任何指示?

I am having trouble with the asset_url working within a Javascript file so I can link correctly to my new pointer/marker graphics. Any pointers on what I'm doing wrong?

我尝试了以下两种方法,但均无济于事:

I tried both of the following and neither worked:

var image = {
  url: "url({{ 'gr_gm-pointer.png' | asset_url }})"
  ...etc
};

var image = {
  url: url({{ 'gr_gm-pointer.png' | asset_url }})
  ...etc
};

我是javascript和Liquid的新手,因此非常感谢您的帮助.谢谢您的提前帮助.

I'm a novice at both javascript and liquid, so any help would be much appreciated. Thank you for your help in advance.

推荐答案

这很旧,但是我为此苦苦挣扎并找到了解决方案,所以我想我应该发布一个答案. google maps标记对象具有icon属性,您可以像这样在液体中调用它:

This is old, but I was struggling with this and found a solution, so I figured I'd post an answer. The google maps marker object has an icon property, you can call it in liquid like this:

var marker = new google.maps.Marker({
      position: latLng,
      map: map,
      icon: '{{ 'your-icon.png' | asset_img_url: '60x' }}'

这篇关于在.js.liquid文件中使用asset_url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 21:00