TAGS :Viewed: 9 - Published at: a few seconds ago

[ Where is documentation for pystache {{.}} ? (dot / period / implicit operator tag) ]

I am looking at some pystache template code that has this:

{{#image_size}}width="{{.}}"{{/image_size}}

It looks like {{.}} gets replaced by the value of image_size. Where is the pystache / mustache documentation that explains this? I looked through the documentation, but the only thing I found was a pystache example with {{.}} but without explanation:

>>> parsed = pystache.parse(u"Hey {{#who}}{{.}}!{{/who}}")

pystache repository and documentation
mustache documentation

Answer 1


That's the "implicit iterator" tag. It's not in the Mustache man page, because it's a later addition to the spec. The best description for it is probably in the Mustache.php documentation:

Mustache provides an "implicit iterator" to access the current scope. It looks like this: {{ . }}.

Inside a section context, the implicit iterator refers to the current loop value:

... but even that isn't perfect :)

Basically, {{ . }} always refers to the current scope. Most of the time, that means the current element in the list that you're iterating over (for example, with an array of strings). In your example, however, {{ image_size }} isn't a list, so {{ . }} simply refers to that value.

It might help to think of Mustache section tags as always representing a loop, and being rendered zero, one, or many times depending on whether your value is nothing, one thing, or many things. In that sense, the "current element of the loop" is just a value when your section tag is something truthy-but-not-a-list.