Crates.io | minijinja-stack-ref |
lib.rs | minijinja-stack-ref |
version | 1.0.21 |
source | src |
created_at | 2022-12-11 13:49:20.800038 |
updated_at | 2024-04-24 08:05:02.663402 |
description | dynamic stack references for MiniJinja |
homepage | https://github.com/mitsuhiko/minijinja |
repository | https://github.com/mitsuhiko/minijinja |
max_upload_size | |
id | 734351 |
size | 31,338 |
MiniJinja-Stack-Ref is a utility crate for MiniJinja that adds support for borrowing of dynamic values from the stack.
use minijinja::{context, Environment};
use minijinja_stack_ref::scope;
let mut env = Environment::new();
env.add_template(
"info",
"app version: {{ state.version }}\nitems: {{ items }}"
)
.unwrap();
let items = [1u32, 2, 3, 4];
let rv = scope(|scope| {
let tmpl = env.get_template("info").unwrap();
tmpl.render(context! {
items => scope.seq_object_ref(&items[..]),
}).unwrap()
});
println!("{}", rv);
For an example have a look at the stack-ref example.
If you like the project and find it useful you can become a sponsor.