liquid-rust icon indicating copy to clipboard operation
liquid-rust copied to clipboard

Add `with` / `for` support to `include` tag.

Open epage opened this issue 6 years ago • 0 comments

Depends on #275

In addition to passing variables to #310, there is a special case of passing a single variable.

There are two forms

  • {% include foo.html with bar %}
    • Create a variable foo that is assigned the value of the expression bar.
    • Equivalent to `{% include foo.html, foo: bar %}
    • Shopify documents this but liquid and Jekyll don't.
  • {% include foo.html for bars %}
    • Include foo multiple times, once for each value in the array bars, passing the value
    • Equivalent to `{% for foo in bars %}{% include foo.html %}{% endfor %}
    • No one documents this

Technically, the ruby implementation just auto-detects if the passed-in value is an array rather than respecting the with and for keywords. I'm guessing this is a bug.

Whats even more interesting is that if no with / for is provided but a variable exists with the template name (e.g. foo in {% include foo.html %}, then that is treated as either a with or a for.

Resources

epage avatar Nov 21 '18 03:11 epage