Skip to content
This repository has been archived by the owner on Nov 24, 2022. It is now read-only.

wrike/minijinja

 
 

Repository files navigation

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 v0.26.0 (minijinja)
    └── serde v1.0.144

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

Minimum Rust Version

MiniJinja's development version requires Rust 1.61 due to limitations with HRTBs in older Rust versions.

MiniJinja 0.20 supports Rust versions down to 1.45. It is possible to write code that is compatible with both 0.20 and newer versions of MiniJinja which should make it possible to defer the upgrade to later.

Related Crates

Sponsor

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

License and Links

About

MiniJinja is a powerful but minimal dependency template engine for Rust

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 98.4%
  • HTML 1.1%
  • Other 0.5%