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.

Load Multiple MiniJinja Templates From A Directory

Code

//! ```cargo
//! [dependencies]
//! minijinja = { version = "1.0.10", features = ['loader'] }
//! ```

use minijinja::{Environment, context, path_loader};

fn main() {
  let template_dir = "/Users/alan/workshop/_examples/minijinja-templates";
  let mut env = Environment::new();
  env.set_loader(path_loader(template_dir));
  let template = env.get_template("alfa.html").unwrap();
  let output = template.render(context!(name => "Alan")).unwrap();
  println!("{}", output);
}

Results

Hello, Alan