stencilproject / Stencil

Stencil is a simple and powerful template language for Swift.
https://stencil.fuller.li
BSD 2-Clause "Simplified" License
2.34k stars 223 forks source link

Using variables for subscripts #174

Closed ilyapuchka closed 6 years ago

ilyapuchka commented 6 years ago

This PR allows to use variables values for subscripting properties of another variables, i.e. given context ["keys": ["one", "two", "three"], "dict": ["one": "I", "two": "II", "three": "III"]] following template will print "I II III".

{% for key in keys %}
{{ dict.key }} 
{% endfor %}

The same applies for index dictionaries and properties This can be useful for ordered dictionary iteration and adds more dynamism to the templates.