使用 Jekyll 的 Liquid 语法,我想在循环中使用 include,但它会出错

With Jekyll's Liquid syntax, I'd like to use include within a loop, but it errors

下面的代码错误说 "Invalid syntax for include tag. File contains invalid characters or sequences: photo-container.html category='korean' image='custom/gallery/korean/1.jpg' Valid syntax: {% include file.ext param='value' param2='value' %}"

      {% for i in (1..1) %}
        {% include photo-container.html category='korean' image='custom/gallery/korean/{{i}}.jpg' %}
      {% endfor %}

我想知道这是否可能,如果可能,如何实现。

在 jekyll 包含中,您可以将参数作为字符串或变量传递,如 {% include p.html param1="my string" param2=myVar %}。但不会处理字符串中的变量。

解决方案是连接您的字符串并将其分配给一个变量。

{% capture myVar %}My string text {{ anyVar }} text end{% end capture %}
or
{% assign myVar="My string text" | append: anyVar | append: "text end" %}
{% include page.html param1=myVar %}