Home

Call A Rust Function With Attributes From A minijinja Template

This calls from a top level function (i.e. it's not on the object that was sent into the template)

rust
```cargo
[dependencies]
minijinja = "1.0.8"
```

use minijinja::{context, Environment};

fn main() {
    let mut env = Environment::new();
    env.add_template("ping_test", "{{ ping('alfa') }}").unwrap();
    env.add_function("ping", ping);
    let tmpl = env.get_template("ping_test").unwrap();
    println!("{}", tmpl.render(context!()).unwrap());
}

fn ping(source: &str) -> String {
    format!("Got: {}", source)
}
results start
~ fin ~