askama
askama copied to clipboard
Mutable local variables
It would be useful to have mutable local variables. With {{ let mut foo }}
syntax maybe?
The idea originates in the @djc comment: https://github.com/djc/askama/issues/669#issuecomment-1104853641
It would be nice if we can do this without explicit syntax. Not sure if that can work...
Wouldn't it surprise rustaceans used to immutable by default variables?
Hmm, I think that wouldn't be a big deal. Remember, you're in the context of a &self
method, so none of the mutability here is externally observable anyway.
Still, with introduction mutability inside templates it could lead to bugs. E.g. let's say we have this structure:
# base.html
{{ let foo = 100 }}
{% include "inner.html" %}
# inner.html
{{ let mut foo = 0 }}
{{ foo += 1 }}
{{ foo }}
Now, let's imagine I forgot or accidentally removed {{ let mut foo = 0 }}
from the inner template. With explicit mutability I get compilation error, without it foo == 101
:)