[英]assigning liquid to javascript variable
var first = 'one',
second = 'two.png';
image = first + second;
console.log('js image: ' + image);
image = '{{ image | asset_url }}';
console.log('liquid image: ' + image);
Produces in the console: 在控制台中产生:
js image: onetwo.png
liquid image:
I cannot get the code to output the code from the liquid filter. 我无法获得从液体过滤器输出代码的代码。 I have tried using
{% raw %}
and looked at a few SO questions ( Shopify: Using variables from {% schema %} in Javascript , Using javascript variables in Shopify liquid , Using asset_url within a .js.liquid file ) to no avail. 我尝试使用
{% raw %}
并查看了几个SO问题( Shopify:使用Javascript中{%schema%}中的 变量,Shopifyliquid中使用javascript变量, .js.liquid文件中使用asset_url )均无济于事。
What am I doing wrong here? 我在这里做错了什么? I am expecting to get:
我期望得到:
liquid image: onetwo.png?123456789
Even removing asset_url
: 甚至删除
asset_url
:
image = '{{ image }}';
Still produces: 仍产生:
liquid image:
Retrieve the variable in the following way: 通过以下方式检索变量:
image = {{ 'image' | asset_url }};
//console log
js image: image.png
liquid image: image.png
After chatting with @Subhrajyoti Das there is a hacky way of doing it. 与@Subhrajyoti Das聊天后,有一种很简单的方法。
Create the full string with dummy text where the actual filename is: 用伪文本创建完整的字符串,其中实际文件名是:
assetString = '{{ 'filename' | asset_url }}'
This produces: 这将产生:
cdn.shopify.com/s/files/0/0000/0000/0000/t/00/assets/filename?0000000000
Then use string replacement to replace 'filename' with the asset variable: 然后使用字符串替换用资产变量替换“文件名”:
image = assetString.replace("filename", image);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.