diff options
author | bott <mhpoin@gmail.com> | 2018-11-13 21:47:01 +0100 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2018-11-14 16:19:29 +0100 |
commit | c7fe975b27f35202365b7b30f1262b99ed3af271 (patch) | |
tree | 78d3c4938617d4bb447e2d3267955486326fe7c7 | |
parent | e7fde0733b25b9e404743b1a49e06b12a0371cb5 (diff) | |
download | askama-c7fe975b27f35202365b7b30f1262b99ed3af271.tar.gz askama-c7fe975b27f35202365b7b30f1262b99ed3af271.tar.bz2 askama-c7fe975b27f35202365b7b30f1262b99ed3af271.zip |
Add assignments documentation
-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 |