#jinja #jinja2 #template

minijinja

a powerful template engine for Rust with minimal dependencies

75 releases (22 stable)

2.0.0-alpha.0 Apr 12, 2024
1.0.21 Apr 24, 2024
1.0.16 Mar 27, 2024
1.0.10 Nov 10, 2023
0.8.2 Nov 8, 2021

#2 in Template engine

Download history 17592/week @ 2024-01-03 20069/week @ 2024-01-10 22385/week @ 2024-01-17 20183/week @ 2024-01-24 22404/week @ 2024-01-31 23321/week @ 2024-02-07 22588/week @ 2024-02-14 27174/week @ 2024-02-21 34151/week @ 2024-02-28 39268/week @ 2024-03-06 41563/week @ 2024-03-13 46345/week @ 2024-03-20 34226/week @ 2024-03-27 34531/week @ 2024-04-03 33860/week @ 2024-04-10 29709/week @ 2024-04-17

137,691 downloads per month
Used in 123 crates (77 directly)

Apache-2.0

640KB
12K SLoC

MiniJinja: a powerful template engine for Rust with minimal dependencies

Build Status License Crates.io rustc 1.61.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 required 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.

$ cargo tree
minimal v0.1.0 (examples/minimal)
└── minijinja v2.0.0-alpha.0 (minijinja)
    └── serde v1.0.144

You can play with MiniJinja online in the browser playground powered by a WASM build of MiniJinja.

Goals:

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

Getting Help

If you are stuck with MiniJinja, have suggestions or need help, you can use the GitHub Discussions.

Similar Projects

These are related template engines for Rust:

  • Askama: Jinja inspired, type-safe, requires template precompilation. Has significant divergence from Jinja syntax in parts.
  • Tera: Jinja inspired, dynamic, has divergences from Jinja.
  • TinyTemplate: minimal footprint template engine with syntax that takes lose inspiration from Jinja and handlebars.
  • Liquid: an implementation of Liquid templates for Rust. Liquid was inspired by Django from which Jinja took it's inspiration.

Sponsor

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

Dependencies

~0.1–1MB
~17K SLoC