Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

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)

Code

```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

Got: alfa