diff options
-rw-r--r-- | askama/src/lib.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/askama/src/lib.rs b/askama/src/lib.rs index 0c1f083..89e438f 100644 --- a/askama/src/lib.rs +++ b/askama/src/lib.rs @@ -119,6 +119,27 @@ //! while `{{ user.name }}` will get the ``name`` field of the ``user`` //! field from the template context. //! +//! ## Assignments +//! +//! Inside code blocks, you can also declare variables or assign values +//! to variables. +//! Assignments can't be imported by other templates. +//! +//! Assignments use the let tag: +//! +//! ```text +//! {% let name = user.name %} +//! {% let len = name.len() %} +//! +//! {% let val -%} +//! {% if len == 0 -%} +//! {% let val = "foo" -%} +//! {% else -%} +//! {% let val = name -%} +//! {% endif -%} +//! {{ val }} +//! ``` +//! //! ## Filters //! //! Values such as those obtained from variables can be post-processed |