Crates.io | axominijinja |
lib.rs | axominijinja |
version | 2.4.0 |
source | src |
created_at | 2024-11-01 15:32:37.005658 |
updated_at | 2024-11-01 15:32:37.005658 |
description | a powerful template engine for Rust with minimal dependencies |
homepage | https://github.com/mitsuhiko/minijinja |
repository | https://github.com/mitsuhiko/minijinja |
max_upload_size | |
id | 1431963 |
size | 698,072 |
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.4.0 (minijinja)
└── serde v1.0.144
Additionally minijinja is also available as an (optionally pre-compiled) command line executable
called minijinja-cli
:
$ curl -sSfL https://github.com/mitsuhiko/minijinja/releases/latest/download/minijinja-cli-installer.sh | sh
$ echo "Hello {{ name }}" | minijinja-cli - -Dname=World
Hello World
You can play with MiniJinja online in the browser playground powered by a WASM build of MiniJinja.
Goals:
serde
compatible typesExample Template:
{% extends "layout.html" %}
{% block body %}
<p>Hello {{ name }}!</p>
{% endblock %}
Invoking from Rust:
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());
}
Here are some interesting Open Source users and use cases of MiniJinja. The examples link directly to where the engine is used so you can see how it's utilized:
HTML Generation:
Structure Generation:
AI Chat Templating:
Data and Processing:
If you are stuck with MiniJinja
, have suggestions or need help, you can use the
GitHub Discussions.
These are related template engines for Rust:
If you like the project and find it useful you can become a sponsor.