paularmstrong/swig — Issue #51: Set tag doesn't set existing variables from inside of statements
Author: imbcmdth
Created: 2012-02-14 16:52:40+00:00
State: open

The set tag operates like a "let" statement in javascript instead of a "var" and doesn't set an existing variable in a higher scope then the one it currently is in:

{% set aCondition = true %}
{% set isTest = false %}
{{ isTest }}
{% if aCondition %}
{% set isTest = true %}
{{ isTest }}
{% endif %}
{{ isTest }}

Prints:

false true false

Expected:

false true true

I would very much like both types of behavior, if possible.

I have a very dirty implementation (a new tag called "reset") but it doesn't do any kind of checking so it will make it's variables global if they haven't already been "set". Not sure this is ideal but it works well enough for my purposes.