From 6010cd390fc3ecd278207d6f3df0cd83fea257f3 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 25 May 2025 15:49:11 +0200 Subject: [PATCH] Add documentation for mutable variables --- book/src/template_syntax.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/book/src/template_syntax.md b/book/src/template_syntax.md index 24c2dd4b..b0494063 100644 --- a/book/src/template_syntax.md +++ b/book/src/template_syntax.md @@ -63,6 +63,15 @@ Like Rust, Askama also supports shadowing variables. {{ foo }} ``` +You can declare variables as mutable with the `mut` keyword: + +```jinja +{# In this example, `foo` is an iterator. If you want to be able to iterate it, +you need it to be mutable #} +{% let mut foo = [1, 2].iter() %} +{{ foo.next().unwrap() }} +``` + For compatibility with Jinja, `set` can be used in place of `let`. ### Borrow rules