Insufficient documentation: "include with" and variable types
I'm having a hard time figuring out how to use variables in Liquid and the documentation is quite scanty. I realize I can do {% assign foo = "bar" %}, but how about arrays and objects? I know they exist as data types in Liquid, but I don't know how to create them inline. (I can use the split filter on a string, but is that all?)
What I'd really like to do is something like {% include "module" with { items: 5, big: true } %} - can this be achieved? Thanks.
Take a look at what a Liquid drop is. That's basically the only way to get "more complex" stuff into Liquid.
Is there some kind of pattern for doing something like the following?
I need to include a fragment in different places, but with some variation - sometimes I need a specific class to be present, other times I need to toggle some content. Having a separate include for every possible combination is not feasible.
/index.liquid
{% block page %}
{% include "module" with { big: true, num_items: 5 } %}
{% endblock %}
/includes/module.liquid
<header{% if module.big %} class="big"{% endif %}>
<h1>Hello</h1>
{% for item in global.menu_items limit:module.num_items %}
<a href="{{ item.href }}">{{ item.text }}</a>
{% endfor %}
</header>
I've discovered that I can assign a value to a variable inside a block and then refer to it by name inside the nested include following it. However, it seems problematic to scatter global variables all over in order to pass some settings to the included fragment...
current docs: https://github.com/Shopify/liquid/wiki/Liquid-for-Designers#variable-assignment
@dalgard I think your idea is correct to use two "global" variables, you can namespace them if you are paranoid.
I'm not aware of a way to pass inline objects using with, but you should totally code that. As far as I know, there is no way to create "objects" or "arrays" of any real sense using liquid. However, you can push it into javascript by printing json inside