Iterating over arrays with mustache

Jeremy picture Jeremy · Oct 17, 2010 · Viewed 20.1k times · Source

How do I obtain a reference to the current element in the iteration?

{{#my_array}}
    <p>{{__what_goes_here?__}}</p>
{{/my_array}}

I hope I am just overlooking the obvious.

Answer

pvande picture pvande · Jun 14, 2012

According to the spec's changelog, the implicit iterator (.) was added in v1.1.0 of the spec. Every Mustache library that implements at least v1.1.0 should support this.

{{#array_of_strings}}<li>{{.}}</li>{{/array_of_strings}}