在Liquid标记调用中使用变量而不是字符串

时间:2020-03-06 15:49:27

标签: jekyll github-pages liquid

我已经检查过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

1 个答案:

答案 0 :(得分:1)

要使用Liquid变量,您需要选择responsive_image_block标签:

{% responsive_image_block %}
  path: {{ post.image }}
{% endresponsive_image_block %}