在 Liquid 标签调用中使用变量而不是字符串
Use variable inside Liquid tag call instead of string
我已经检查过 this solution,它似乎无法解决我的问题。我在将 post.image
变量名称传递给标记 responsive_image
时遇到问题。如果我像 {% responsive_image path: assets/img/ar-7.jpg %}
这样传递字符串,它可以正常工作,但我没有找到如何将变量传递给它的方法。有什么想法吗?
1) 我认为这可行,不幸的是传递的是字符串 post.image
而不是变量。注释代码是我需要更改为响应式图像的工作示例。
{% if post.image %}
{% responsive_image path: post.image %}
<!-- <img class="has-ratio" src="{{post.image}}" /> -->
{% endif %}
Invalid image path specified: "post.image"
Liquid Exception: unable to open image `/Users/.../Documents/Apps/Jekyll/wtc-mbp/post.image': No such file or directory @ error/blob.c/OpenBlob/2881 in .html
2) this answer 的解决方案不起作用
{% if post.image %}
{% assign path = post.image %}
{% responsive_image path %}
{% endif %}
Invalid image path specified: nil
Liquid Exception: no decode delegate for this image format `' @ error/constitute.c/ReadImage/566 in .html
3)另一个想法也不行
{% if post.image %}
{% assign path = post.image %}
{% responsive_image path: path %}
{% endif %}
Invalid image path specified: "path"
Liquid Exception: unable to open image `/Users/.../Documents/Apps/Jekyll/wtc-mbp/path': No such file or directory @ error/blob.c/OpenBlob/2881 in .html
要使用 Liquid 变量,您需要选择 responsive_image_block
标签:
{% responsive_image_block %}
path: {{ post.image }}
{% endresponsive_image_block %}
我已经检查过 this solution,它似乎无法解决我的问题。我在将 post.image
变量名称传递给标记 responsive_image
时遇到问题。如果我像 {% responsive_image path: assets/img/ar-7.jpg %}
这样传递字符串,它可以正常工作,但我没有找到如何将变量传递给它的方法。有什么想法吗?
1) 我认为这可行,不幸的是传递的是字符串 post.image
而不是变量。注释代码是我需要更改为响应式图像的工作示例。
{% if post.image %}
{% responsive_image path: post.image %}
<!-- <img class="has-ratio" src="{{post.image}}" /> -->
{% endif %}
Invalid image path specified: "post.image"
Liquid Exception: unable to open image `/Users/.../Documents/Apps/Jekyll/wtc-mbp/post.image': No such file or directory @ error/blob.c/OpenBlob/2881 in .html
2) this answer 的解决方案不起作用
{% if post.image %}
{% assign path = post.image %}
{% responsive_image path %}
{% endif %}
Invalid image path specified: nil
Liquid Exception: no decode delegate for this image format `' @ error/constitute.c/ReadImage/566 in .html
3)另一个想法也不行
{% if post.image %}
{% assign path = post.image %}
{% responsive_image path: path %}
{% endif %}
Invalid image path specified: "path"
Liquid Exception: unable to open image `/Users/.../Documents/Apps/Jekyll/wtc-mbp/path': No such file or directory @ error/blob.c/OpenBlob/2881 in .html
要使用 Liquid 变量,您需要选择 responsive_image_block
标签:
{% responsive_image_block %}
path: {{ post.image }}
{% endresponsive_image_block %}