home ~ projects ~ socials

Basic Template File Input And Output With MiniJinja in Rust

---
[dependencies]
minijinja = { version = "2.9.0" }
---

use minijinja::{Environment, context};
use std::fs;

fn main() {
  let mut env = Environment::new();
  let template_string = fs::read_to_string("minijinja/basic-template-input.html").unwrap();
  env.add_template("main-template", &template_string).unwrap();
  let tmpl = env.get_template("main-template").unwrap();
  let output = tmpl.render(context!(title => "Alfa Bravo")).unwrap();
  fs::write("minijinja/basic-template-output.html", output).unwrap();
  println!("done making");
}
Output:
done making

Notes

  • There's no error handling in this example. It's primary purpose is to show that actions that need to happen.
-- end of line --