aboutsummaryrefslogtreecommitdiffstats
path: root/askama
diff options
context:
space:
mode:
authorLibravatar Vicente Ramirez Perea <vicente.ramirez.perea@gmail.com>2019-03-05 22:47:17 +0100
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2019-03-18 10:19:48 +0100
commit5b2e9cf99274827079f70f10966f6284d075e624 (patch)
tree0ad69e32d5aa59defb1dfbdc1e684ca2de8d608d /askama
parent84d81e101bc706cfe85320df39c1f32828225153 (diff)
downloadaskama-5b2e9cf99274827079f70f10966f6284d075e624.tar.gz
askama-5b2e9cf99274827079f70f10966f6284d075e624.tar.bz2
askama-5b2e9cf99274827079f70f10966f6284d075e624.zip
Documenting feature render in template
Diffstat (limited to '')
-rw-r--r--askama/src/lib.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/askama/src/lib.rs b/askama/src/lib.rs
index de25c3e..d1c18c5 100644
--- a/askama/src/lib.rs
+++ b/askama/src/lib.rs
@@ -371,6 +371,36 @@
//! recursion. This is because the `Display` implementation for that expression
//! will in turn evaluate the expression and yield `self` again.
//!
+//! ## Template in template
+//!
+//! Using expressions, it is possible to render a template inside another one. This functionality
+//! allows modularize template sections and inject them in another template. This
+//! facilitates testing, and reusing part of templates.
+//!
+//! ```rust
+//! use askama::Template;
+//! #[derive(Template)]
+//! #[template(source = "Section 1: {{ s1.render().unwrap() }}", ext = "txt")]
+//! struct RenderInPlace<'a> {
+//! s1: SectionOne<'a>
+//! }
+//! #[derive(Template)]
+//! #[template(source = "A={{ a }}\nB={{ b }}", ext = "txt")]
+//! struct SectionOne<'a> {
+//! a: &'a str,
+//! b: &'a str,
+//! }
+//! let t = RenderInPlace{s1: SectionOne{a: "a", b: "b"}};
+//! assert_eq!(t.render().unwrap(), "Section 1: A=a\nB=b")
+//! ```
+//!
+//! See the example
+//! [render in place](https://github.com/djc/askama/blob/master/testing/tests/render_in_place.rs)
+//! using a vector of templates in a for block.
+//!
+//! See the example [using enums](https://github.com/djc/askama/blob/master/testing/tests/render_with_enums.rs)
+//! for another use case. You can use different template parts depending on the context.
+//!
//! ## Comments
//!
//! Askama supports block comments delimited by `{#` and `#}`.