minijinja-stack-ref

Crates.iominijinja-stack-ref
lib.rsminijinja-stack-ref
version1.0.21
sourcesrc
created_at2022-12-11 13:49:20.800038
updated_at2024-04-24 08:05:02.663402
descriptiondynamic stack references for MiniJinja
homepagehttps://github.com/mitsuhiko/minijinja
repositoryhttps://github.com/mitsuhiko/minijinja
max_upload_size
id734351
size31,338
Armin Ronacher (mitsuhiko)

documentation

README

MiniJinja-Stack-Ref

Build Status License Crates.io rustc 1.61.0 Documentation

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.

Sponsor

If you like the project and find it useful you can become a sponsor.

License and Links

Commit count: 1139

cargo fmt