Jekyll 包含变量数组值

Jekyll 包含变量数组值,jekyll,liquid,Jekyll,Liquid,我有一些组件按钮: {% assign class = "c-button " | append: include.class %} {% assign type = include.type | default: "button" %} {% assign content = include.content %} {% if content %} <button class="{{ class }}" type="{{ type }}">{{ conten

我有一些组件按钮:

{% assign class = "c-button " | append: include.class %}
{% assign type = include.type | default: "button" %}
{% assign content = include.content %}

{% if content %}
  <button class="{{ class }}"
          type="{{ type }}">{{ content }}</button>
{% endif %}
我收到这个错误:

液体异常:include标记的语法无效:type=“button” content=site.data.contentful.spaces.links.navbar。[0]类= “漂亮按钮”有效语法:{%include file.ext param='value' param2='value%}

无法将数组值指定给包含变量吗


谢谢你的帮助

include标记当前不解析具有类似
navbar[0]
的语法的变量值。仅限“简单带引号的字符串”或“包含字母数字和/或连字符的变量”

content=site.data.contentful.spaces.links.navbar[0]。项目名称将被标记
,但
content=site.data.contentful.spaces.links.navbar.item\u名称将被传递以进行评估

您可以使用
capture
标记预先评估标记的变量,然后通过简单变量插入:

{% capture my_content %} site.data.contentful.spaces.links.navbar[0].item_name {% endcapture %}
{% include components/button.html type = "button" content = my_content class = "pretty-button" %}

注意,由于parse regex中忽略多行字符串的错误,include标记定义在一行中。该补丁包含在
jekyll-3.8.0.pre.rc1

中,include标记当前不解析具有类似
navbar[0]
语法的变量值。仅限“简单带引号的字符串”或“包含字母数字和/或连字符的变量”

content=site.data.contentful.spaces.links.navbar[0]。项目名称将被标记
,但
content=site.data.contentful.spaces.links.navbar.item\u名称将被传递以进行评估

您可以使用
capture
标记预先评估标记的变量,然后通过简单变量插入:

{% capture my_content %} site.data.contentful.spaces.links.navbar[0].item_name {% endcapture %}
{% include components/button.html type = "button" content = my_content class = "pretty-button" %}

注意,由于parse regex中忽略多行字符串的错误,include标记定义在一行中。该修补程序包含在
jekyll-3.8.0.pre.rc1
{%capture button\u content%}{{site.data.contentful.spaces.links.navbar[0]中。解决方案是项目名称}{%endcapture%}。谢谢{%capture button_content%}{{site.data.contentful.spaces.links.navbar[0].item_name}{%endcapture%}就是解决方案。谢谢