jekyll - 在 Liquid 标签调用中使用变量而不是字符串
问题描述
我已经检查过这个解决方案,它似乎对我的问题不起作用。我在将post.image
变量名称传递给 tag 时遇到问题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)这个答案的解决方案,不起作用
{% 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 %}
推荐阅读
- javascript - 如何从 html 页面调用 react 道具
- python - 为什么在 python 中下载图像时必须同时保存 png 和 txt 文件?
- javascript - 运行 npm run make 时出现“类型错误:无法读取未定义的属性‘日期’”
- android - 我可以将手机用作 VIsual Studio 2019 的模拟器吗?
- java - Android Studio ...在意图中将查询值传递给互联网搜索
- revit-api - Revit 在类型目录中使用什么字符编码?
- graph - 此图的名称/类型
- docker - 通过 Azure 应用服务的 Terraform 脚本将变量传递给 Docker Compose
- types - Julia:是否可以将参数字典传递给函数?
- amazon-web-services - 在 AWS Elastic Beanstalk 上运行烧瓶应用程序时出现 504 网关超时