Jekyll 将数组传递给要循环的include

Jekyll 将数组传递给要循环的include,jekyll,liquid,Jekyll,Liquid,我有一个include,根据传入的内容可以有>1个按钮 目前,我的工作包括: {% if include.buttons %} {% for button in include.buttons %} <a class="{{ button.classes }}" href="{{ button.url }}">{{ button.title }}</a> {% endfor %} {% endif %} 我无法解决的是如何将数据正确地传递到inc

我有一个include,根据传入的内容可以有>1个按钮

目前,我的工作包括:

{% if include.buttons %}
   {% for button in include.buttons %}
      <a class="{{ button.classes }}" href="{{ button.url }}">{{ button.title }}</a>
   {% endfor %}
{% endif %}

我无法解决的是如何将数据正确地传递到include,以便循环使用。

问题是将数据分配为数组。在液体中不能直接使用。一个解决办法是玩

但是,使用jekyll可以通过提供阵列。只需将您的按钮放入一个文件中,例如_data\buttons.yml,其中包含:

现在,您可以在帖子/页面的yaml标题中添加一个引用,如下所示:

---
your other yaml options....
buttons: postXX
---
最后,分配按钮并像在代码中那样包含它们

{% assign buttons = site.data.buttons[page.buttons] %}
{% include header.html
   buttons=buttons
%}

问题是将数据分配为数组。在液体中不能直接使用。一个解决办法是玩

但是,使用jekyll可以通过提供阵列。只需将您的按钮放入一个文件中,例如_data\buttons.yml,其中包含:

现在,您可以在帖子/页面的yaml标题中添加一个引用,如下所示:

---
your other yaml options....
buttons: postXX
---
最后,分配按钮并像在代码中那样包含它们

{% assign buttons = site.data.buttons[page.buttons] %}
{% include header.html
   buttons=buttons
%}

使用Liquid,您无法使用{%assign myArray=[one,two,three]}这样的文字表达式创建数组

您只能:

创建空的:{%assign emptyArray=| split:%} 从字符串创建一个:{%assign myArray=一二三| split:%} 然后,您可以操纵阵列:

向数组中添加元素:按或移位 从数组中删除元素:pop或unshift 将两个数组合并到 等等
因此,您的数组只能来自liquid数组操作或配置、数据文件或页面首页中包含的某些数据。

对于liquid,您不能使用{%assign myArray=[one,two,three]}这样的文字表达式创建数组

您只能:

创建空的:{%assign emptyArray=| split:%} 从字符串创建一个:{%assign myArray=一二三| split:%} 然后,您可以操纵阵列:

向数组中添加元素:按或移位 从数组中删除元素:pop或unshift 将两个数组合并到 等等 所以,您的数组只能来自液体数组操作或配置、数据文件或页面首页中包含的某些数据