paularmstrong/swig — pull request #212 by iamjochem (2013-03-26 13:41:43+00:00)
Title: add a [failing] test for setting object literal property using the "set" tag based on vars in the current template context

this PR contains a couple of additions to the unit tests for the "set" tag showing that it is not possible to use existing template vars to create a new object literal with "set".

Why would that be useful? I would like to be able to use an "include" in "for" loop, e.g.

```
{% for job in jobs %}
{% set ctx = {job: job, foo: 'bar'} %}
{% include 'partials/job-row.html' with ctx %}
{% endfor %}
```

I'd like to be able to have reusable 'item' templates that are included within a loop from multiple templates ... currently there seems no way to supply the included template with a suitable 'context' (containing the current item in the outer loop)

The added tests define the problem ... I am currently at a loss as to how implement the extension to the "set" tag that I am suggesting.

Questions:

1. Is extending the "set" tag to allow setting of object literal properties to the value of existing template vars something you would consider including?

2. Is there a easier/better way of achieving the same result (i.e. should I be using the template engine differently to tackle the problem I have)?

3. assuming 'yes' for question 1 and 'no' for question 2, would you consider implementing the requested change to the "set" tag? if not would you be able to give a hint or two as to where to start with regard to implementing this so I could have a stab at it myself?