【问题标题】:How to use Liquid include variable within a for loop?如何在 for 循环中使用 Liquid 包含变量?
【发布时间】:2018-01-14 01:13:55
【问题描述】:

我有这个 Liquid 模板,看起来像这样:

# /_includes/slideshow.html
{% for image in {{ include.images }} %}
    ...
{% endfor %}

我正在尝试将其与 YAML 文件(用于我的 Jekyll 网站)一起使用,如下所示:

# /index.md
{% include slideshow.html images='site.data.homepage_images' %}

我看到此失败的原因是因为我的包含变量 {{ include.images }} 解析为 for 循环中的 string。有没有不同的方法可以做到这一点?我对 Liquid、YAML、Jekyll 以及 Web 开发还很陌生,因此非常感谢您在这方面的任何帮助!

(注意:如果我将{{ include.images }} 替换为site.data.homepage_images,问题就会消失。)

此外,我这样做的原因(以及为什么粗略的修复不是我正在寻找的解决方案)是为了能够在我的网站周围的其他地方注入我的图像幻灯片。以这种方式滥用我的包含变量会节省大量代码。

【问题讨论】:

    标签: jekyll liquid


    【解决方案1】:

    for 循环中的正确语法是:{% for image in include.images %}

    【讨论】:

    • 啊,我现在明白了。它位于 Jekyll 的 Includes 页面的更下方。无论如何,感谢您的帮助!
    猜你喜欢
    • 2014-11-21
    • 2015-10-12
    • 2011-07-11
    • 1970-01-01
    • 2016-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-28
    相关资源
    最近更新 更多