Andrew Chaa
Andrew Chaa

Reputation: 6388

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

The following code error saying "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 %}

I wonder if it's possible, and if it is, how.

Upvotes: 1

Views: 451

Answers (1)

David Jacquel
David Jacquel

Reputation: 52829

In jekyll inclusions, you can pass parameters as strings or variables like {% include p.html param1="my string" param2=myVar %}. But a variable in a string will not be processed.

The solution is to concatenate your string and assign it to a variable.

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

Upvotes: 1

Related Questions