Open kaygro opened 6 years ago
The for
loop tag is from the Stencil library itself. Stencil builds up a stack whenever a for loop is executed, or when another template is included. We've added our own tags that use this same stack mechanism, for example the macro
tag (https://github.com/SwiftGen/StencilSwiftKit/blob/master/Documentation/tag-macro.md).
If you'd like to propose a change to the for
tag, I'd recommend making an issue in the appropriate repository (https://github.com/kylef/Stencil/issues), as we can't override/modify existing Stencil tags. If you'd like to propose new tags/filters, we could discuss this here if appropriate.
I did check the sources of the stencil library and currently they actually appear to implement override sematics for extensions by same tags. Though I'll do an experiment on this later.
@kaygro while this is really unlike done in programming languages, this is inline with Jinja 2 behaviour, which I guess was the main inspiration for Stencil. It does though provide namespace feature to solve this issue. http://jinja.pocoo.org/docs/2.10/templates/
When mutating a variable inside a for-loop, these changes get reverted on loop exit. This is quite unlike most programming languages. Unfortunately this makes you use more boilerplate code inside templates than necessary.