Voog.com

Using variables as dynamic keys

Liquid supports using String literals as Hash keys or Array indices. For example, instead calling page.data.foo you can use page.data['foo']. Using variables with this functionality allows for some cool tricks.
{% assign my_num = 3 %}

{% for i in (1..my_num) %}
{% assign var = "bar_" | append: i %}
{{ page.data.foo[var].title }}
{% endfor %}

The above example is analogous with

{{ page.data.foo.bar_1.title }}
{{ page.data.foo.bar_2.title }}
{{ page.data.foo.bar_3.title }}