liquid-rust
liquid-rust copied to clipboard
Add `with` / `for` support to `include` tag.
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 expressionbar
. - Equivalent to `{% include foo.html, foo: bar %}
- Shopify documents this but liquid and Jekyll don't.
- Create a variable
-
{% include foo.html for bars %}
- Include
foo
multiple times, once for each value in the arraybars
, passing the value - Equivalent to `{% for foo in bars %}{% include foo.html %}{% endfor %}
- No one documents this
- Include
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