MiniJinja is a powerful but minimal dependency template engine for Rust which is based on the syntax and behavior of the Jinja2 template engine for Python.
It's implemented on top of serde
and only has it as a single dependency. It
supports a range of features from Jinja2 including inheritance, filters and
more. The goal is that it should be possible to use some templates in Rust
programs without the fear of pulling in complex dependencies for a small
problem. Additionally it tries not to re-invent something but stay in line
with prior art to leverage an already existing ecosystem of editor integrations.
{% extends "layout.html" %}
{% block body %}
<p>Hello {{ name }}!</p>
{% endblock %}
use minijinja::{Environment, context};
fn main() {
let mut env = Environment::new();
env.add_template("hello.txt", "Hello {{ name }}!").unwrap();
let template = env.get_template("hello.txt").unwrap();
println!("{}", template.render(context! { name => "World" }).unwrap());
}
MiniJinja supports Rust versions down to 1.43 at the moment. For the order preservation feature Rust 1.49 is required as it uses the indexmap dependency which no longer supports older Rust versions.
Note that we currently cannot run tests against 1.43.0 due to our tests depending on insta which in turn also depends on indexmap.
If you like the project and find it useful you can become a sponsor.
- Documentation
- Examples
- Issue Tracker
- License: Apache-2.0