goods/tmpl — Issue #5: Ranges
Author: zeebo
Created: 2012-03-04 18:17:20+00:00
State: open
Labels: question

Currently how I'm thinking of ranges is, say given the list ['foo', 'bar', 'baz'] as the current context, the output of

{% range . %}{% .key %}: {% val %}
{% end range %}

is

0: foo
1: bar
2: baz

Then the question is how does it interact with popping? say we have the context:

{
'foo': 'foo',
'list': ['foo', 'bar', 'baz']
}

and the template

{% range .list %}{% block foo %}{% end block %}{% end range %}

how would we get the foo block to access the foo value of the upper context?

{% block foo %}{% $$.foo %}{% end block %}
{% block foo %}{% $.foo %}{% end block %}

The first is motivated by the idea that the range pushes a {key: key, val: val} on to the context. The second is motivated by the current context being at .list. Also, should we allow a syntax for naming the key/values? Like

{% range .list as k1 v1 %}{% end range %}

Thoughts?