#jinja #jinja2 #templates

minijinja

a powerful template engine for Rust with minimal dependencies

17 releases (breaking)

0.15.0 Mar 20, 2022
0.13.0 Jan 23, 2022
0.10.0 Dec 29, 2021
0.8.2 Nov 8, 2021

#7 in Template engine

Download history 741/week @ 2022-01-29 1397/week @ 2022-02-05 832/week @ 2022-02-12 1100/week @ 2022-02-19 1060/week @ 2022-02-26 1276/week @ 2022-03-05 1942/week @ 2022-03-12 2487/week @ 2022-03-19 3012/week @ 2022-03-26 2721/week @ 2022-04-02 2129/week @ 2022-04-09 2227/week @ 2022-04-16 3079/week @ 2022-04-23 2503/week @ 2022-04-30 3367/week @ 2022-05-07 3130/week @ 2022-05-14

12,627 downloads per month
Used in 11 crates (6 directly)

Apache-2.0

335KB
7.5K SLoC

MiniJinja: a powerful template engine for Rust with minimal dependencies

Build Status License Crates.io rustc 1.43.0 Documentation

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.

Example Template

{% extends "layout.html" %}
{% block body %}
  <p>Hello {{ name }}!</p>
{% endblock %}

API

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());
}

Minimum Rust Version

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.

Sponsor

If you like the project and find it useful you can become a sponsor.

License and Links

Dependencies

~135–580KB
~12K SLoC