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.
Example
{% assign sizes = hash %}
{% assign sizes["S"] = "Small" %}
{% assign sizes["M"] = "Medium" %}
{% assign sizes["L"] = "Large" %}
{% assign size_abbreviations = sizes | keys %}
{% assign size_labels = sizes | values %}
{% for keyval in sizes %}
{% assign size_abbreviation = keyval[0] %}
{% assign size_label = keyval[1] %}
{{ size_abbreviation }}: {{ size_label }}
{% endfor %}
Last updated
Was this helpful?