mirror of
https://github.com/askama-rs/askama.git
synced 2025-10-02 15:25:19 +00:00
Use efficient method for nested template rendering
This commit is contained in:
parent
b801724738
commit
ecafb9b10a
@ -304,7 +304,7 @@ testing and reuse.
|
|||||||
```rust
|
```rust
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
#[template(source = "Section 1: {{ s1.render().unwrap() }}", ext = "txt")]
|
#[template(source = "Section 1: {{ s1 }}", ext = "txt")]
|
||||||
struct RenderInPlace<'a> {
|
struct RenderInPlace<'a> {
|
||||||
s1: SectionOne<'a>
|
s1: SectionOne<'a>
|
||||||
}
|
}
|
||||||
@ -315,6 +315,7 @@ struct SectionOne<'a> {
|
|||||||
a: &'a str,
|
a: &'a str,
|
||||||
b: &'a str,
|
b: &'a str,
|
||||||
}
|
}
|
||||||
|
|
||||||
let t = RenderInPlace { s1: SectionOne { a: "a", b: "b" } };
|
let t = RenderInPlace { s1: SectionOne { a: "a", b: "b" } };
|
||||||
assert_eq!(t.render().unwrap(), "Section 1: A=a\nB=b")
|
assert_eq!(t.render().unwrap(), "Section 1: A=a\nB=b")
|
||||||
```
|
```
|
||||||
@ -344,7 +345,7 @@ use askama::Template;
|
|||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
#[template(source = r#"
|
#[template(source = r#"
|
||||||
//! {% for item in children %}
|
//! {% for item in children %}
|
||||||
{{ item.render().unwrap() }}
|
{{ item }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
"#, ext = "html", escape = "none")]
|
"#, ext = "html", escape = "none")]
|
||||||
struct Item<'a> {
|
struct Item<'a> {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
Section 1: {{ s1.render().unwrap() }}
|
Section 1: {{ s1 }}
|
||||||
Section 2: {{ s2.render().unwrap()|safe }}
|
Section 2: {{ s2|safe }}
|
||||||
Section 3 for:
|
Section 3 for:
|
||||||
{% for s in s3.as_slice() -%}
|
{% for s in s3.as_slice() -%}
|
||||||
* {{ s.render().unwrap() }}
|
* {{ s }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user