askama
askama copied to clipboard
Pass variables to includes
Is there a way to pass parameters to the includes
?
Something like
// page.rs
#[derive(Template)]
#[template(path = "includes/widget.html")]
struct Widget {
a: String,
b: String,
}
#[derive(Template)]
#[template(path = "page.html")]
struct Page {
a: String,
widget: Widget,
}
// page.html
<span>{{ a }}</span>
{% includes includes/widget.html {{widget}} %}
// includes/widget.html
<span>{{ a }}</span>
<span>{{ b }}</span>
No; the include should just have access to its including scope. I think typically you would solve this by import
ing a macro
definition from a particular file.
@djc Can you give me an example on importing that macro definition from a particular file?
Have a look at the test: https://github.com/djc/askama/blob/master/testing/tests/macro.rs#L16