Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mutations inside forloop not visible outside #75

Open
kaygro opened this issue Jan 31, 2018 · 3 comments
Open

Mutations inside forloop not visible outside #75

kaygro opened this issue Jan 31, 2018 · 3 comments

Comments

@kaygro
Copy link

kaygro commented Jan 31, 2018

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.

@djbe
Copy link
Member

djbe commented Jan 31, 2018

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.

@kaygro
Copy link
Author

kaygro commented Feb 2, 2018

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.

@ilyapuchka
Copy link
Collaborator

@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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants