There are two ways to pass variables to a Snippet, which can be used concurrently or separately:
- Using with (a single variable)
- Using a chain of key:value declarations (multiple variables)
{% include 'snippet-name' with value key1:value1 key2:value2 %}
If not including separators is too crazy looking, then feel free to put some commas in:
{% include 'snippet-name' with value, key1:value1, key2:value2 %}
In a Snippet called boss.liquid, write the following.
<h3>{{ boss }}</h3>
<ul>
<li>{{ listIem1 }}</li>
<li>{{ listIem2 }}</li>
</ul>
The tag {{ boss }}
will take on the value of anything passed to the Snippet using with. The other tags will take on the value of their matching key.
In product.liquid, add {% include 'boss' with 'boss things' listIem1: 'accounting' listIem2: 'finance' %}
below the heading to get this result:
In product-loop.liquid add {% include 'boss' with 'easy time' listIem1: 'candy' listIem2: 'popsiciles' %}
to get this whole different result:
Or, add some variable to make it interesting:
{% include 'boss' with collection.title listIem1: product.type listIem2: product.vendor %}