janl/mustache.js — pull request #260 by techhead (2012-10-01 14:27:04+00:00)
Title: Exposed current Context to lambdas via Mustache.currentContext

This is an optional feature that does not break compatibility unless you use it ;)

I would like to see these properties added to the Mustache spec at some point in the future if consensus can be reached on the best way to expose them, namely the current index of an item in an array and a reference to that array (see the definition of the forEach callback, https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/forEach). But this patch also exposes the entire current context stack to a lambda.

It is NOT my suggestion that a global property named Mustache.currentContext be defined for the spec but that the spec should define a way in which to expose this information.

See test/_files/current_context* for examples on utility.

current_context_oddeven.js
```javascript
({
rows: [1,2,3],
oddeven: function() {
var ctx = Mustache.currentContext;
return (ctx.index % 2) ? 'even' : 'odd';
}
})
```

```html

{{#rows}}
{{.}}

{{/rows}}

```