From c7fe975b27f35202365b7b30f1262b99ed3af271 Mon Sep 17 00:00:00 2001 From: bott Date: Tue, 13 Nov 2018 21:47:01 +0100 Subject: Add assignments documentation --- askama/src/lib.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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 -- cgit