【问题标题】:Use variable inside Liquid tag call instead of string在 Liquid 标签调用中使用变量而不是字符串
【发布时间】:2020-06-19 09:22:00
【问题描述】:

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

【问题讨论】:

    标签: jekyll github-pages liquid


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2021-01-23
      • 1970-01-01
      • 2013-07-24
      • 1970-01-01
      • 1970-01-01
      • 2017-02-26
      • 2011-11-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多