hash
The hash keyword literal may be used in any Liquid code to instantiate a hash.
Hashes support assignment by key. The keys and values filters may be used to quickly access an array of hash keys or values, respectively.
The term "hash" comes from Ruby. In Ruby (docs), "A Hash is a dictionary-like collection of unique keys and their values."
In Mechanic's Liquid implementation, a hash can only have string keys.

Example

1
{% assign sizes = hash %}
2
{% assign sizes["S"] = "Small" %}
3
{% assign sizes["M"] = "Medium" %}
4
{% assign sizes["L"] = "Large" %}
5
​
6
{% assign size_abbreviations = sizes | keys %}
7
{% assign size_labels = sizes | values %}
8
​
9
{% for keyval in sizes %}
10
{% assign size_abbreviation = keyval[0] %}
11
{% assign size_label = keyval[1] %}
12
​
13
{{ size_abbreviation }}: {{ size_label }}
14
{% endfor %}
Copied!
Last modified 3mo ago
Copy link
Edit on GitHub
Contents
Example