For a data.yml like
key1: value1
key2: value2
...
How should I get a list of keys/values in a forloop? I tried
{%- for datum in site.data.data -%}
{{ datum }}
{%- endfor -%}
and I got key1value1key2value2...
. How to separate them?
For a data.yml like
key1: value1
key2: value2
...
How should I get a list of keys/values in a forloop? I tried
{%- for datum in site.data.data -%}
{{ datum }}
{%- endfor -%}
and I got key1value1key2value2...
. How to separate them?
It is poorly documented, but datum
is an array of key and value, so datum[0]
is the key, and datum[1]
is the value. This is only documented in Liquid’s old Github Wiki, but not in the official Liquid site. Old Wiki:
https://github.com/Shopify/liquid/wiki/Liquid-for-Designers#allowed-collection-types
Thank you, @chuckhoupt! A while ago I also searched madly how to access key & value when iterating a hash. Forget how I solved it then :).
Thank you so much for your help!!!