diff options
author | Bernhard Schuster <bernhard@ahoi.io> | 2019-04-24 12:56:29 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2019-04-28 21:48:32 +0200 |
commit | a778ad5f3ce1f9fdcb2834357fb735ad563173a4 (patch) | |
tree | 81a5f79dd3515bcdb96aefd7b4b4761293083a86 | |
parent | e29792e90ce438875a13becdeb9c030b1d3132e4 (diff) | |
download | askama-a778ad5f3ce1f9fdcb2834357fb735ad563173a4.tar.gz askama-a778ad5f3ce1f9fdcb2834357fb735ad563173a4.tar.bz2 askama-a778ad5f3ce1f9fdcb2834357fb735ad563173a4.zip |
docs/recursive: add documentation hints for recursive structures
Closes #220
-rw-r--r-- | askama/src/lib.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/askama/src/lib.rs b/askama/src/lib.rs index a7de51a..cf6bf30 100644 --- a/askama/src/lib.rs +++ b/askama/src/lib.rs @@ -402,6 +402,29 @@ //! //! Askama supports block comments delimited by `{#` and `#}`. //! +//! +//! ## Recursive Structures +//! +//! Recursive implementations should preferably use a custom iterator and +//! use a plain loop. If that is not doable, call `.render()` +//! directly by using an expression as shown below. +//! Including self does not work, see #105 and #220 . +//! +//! ```rust +//! use askama::Template; +//! +//! #[derive(Template)] +//! #[template(source = r#" +//! //! {% for item in children %} +//! {{ item.render().unwrap() }} +//! {% endfor %} +//! "#, ext = "html", escape = "none")] +//! struct Item<'a> { +//! name: &'a str, +//! children: &'a [Item<'a>], +//! } +//! ``` +//! //! # Optional functionality //! //! ## Rocket integration |