0
votes

I've got some component button:

{% 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 %}

Now i want include a button with some values and content out an array:

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

I receive this error:

Liquid Exception: Invalid syntax for include tag: type = "button" content = site.data.contentful.spaces.links.navbar.[0] class = "pretty-button" Valid syntax: {% include file.ext param='value' param2='value' %}

Is it not possible to assign an array value to a include variable?

Thanx for any help!

1

1 Answers

2
votes

The include tag currently does not parse variable values with syntaxes like navbar[0]. Only "simple quoted strings" or "variables comprising alphanumericals and/or a hyphen".

content = site.data.contentful.spaces.links.navbar[0].item_name will be flagged
but content = site.data.contentful.spaces.links.navbar.item_name will be passed through for evaluation.

You can use the capture tag to pre-eval the flagged variable and then inserted via a simple variable:

{% 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" %}

Note that include tag is defined in a single line due to a bug in the parse regex that ignores multiline strings. The patch is included in jekyll-3.8.0.pre.rc1