42 releases (21 stable)

1.0.21 Apr 24, 2024
1.0.16 Mar 27, 2024
1.0.10 Nov 10, 2023
1.0.5 Jul 18, 2023
0.27.0 Dec 11, 2022

#471 in Template engine

Download history 2/week @ 2024-01-18 17/week @ 2024-02-22 11/week @ 2024-02-29 216/week @ 2024-03-14 255/week @ 2024-03-21 67/week @ 2024-03-28 288/week @ 2024-04-04 98/week @ 2024-04-11 94/week @ 2024-04-18 56/week @ 2024-04-25 32/week @ 2024-05-02

387 downloads per month
Used in curlz

Apache-2.0

670KB
13K SLoC

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.

Dependencies