包括可变数组值



我有一些组件按钮:

{% 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 components/button.html
  type = "button"
  content = site.data.contentful.spaces.links.navbar[0].item_name
  class = "pretty-button"
%}

我收到此错误:

液体异常:无效的语法include tag:type =" button" content = site.data.contentful.spaces.links.navbar。[0]class = " better-utton"有效语法:{%include file.ext param ='value' param2 ='value'%}

不可能将数组值分配给a include变量?

thanx提供任何帮助!

Incluber标签当前不会用诸如navbar[0]之类的语法解析变量值。只有"简单引用的字符串"或"包含字母数字和/或连字符的变量"。

content = site.data.contentful.spaces.links.navbar[0].item_name将被标记
,但是 content = site.data.contentful.spaces.links.navbar.item_name 将通过进行评估。

您可以使用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" %}

注意,Include标签是在单行中定义的,这是由于Parse Regex中的一个错误忽略了多行字符串。该补丁包含在jekyll-3.8.0.pre.rc1

相关内容

最新更新