112 releases (29 stable)

Uses new Rust 2024

new 2.0.0-alpha.5 May 11, 2026
2.0.0-alpha.2 Mar 3, 2026
1.20.1 Oct 30, 2025
1.20.0 May 27, 2024
0.1.2 Jun 5, 2016

#4 in Template engine

Download history 266050/week @ 2026-01-24 304115/week @ 2026-01-31 333371/week @ 2026-02-07 326621/week @ 2026-02-14 342352/week @ 2026-02-21 416761/week @ 2026-02-28 445956/week @ 2026-03-07 387840/week @ 2026-03-14 376595/week @ 2026-03-21 356230/week @ 2026-03-28 407532/week @ 2026-04-04 419334/week @ 2026-04-11 381080/week @ 2026-04-18 410187/week @ 2026-04-25 425951/week @ 2026-05-02 400480/week @ 2026-05-09

1,681,668 downloads per month
Used in 1,411 crates (801 directly)

MIT license

485KB
11K SLoC

Tera

See migration guide.


lib.rs:

Tera

A powerful, fast and easy-to-use template engine for Rust

This crate provides an implementation of the Tera template engine, which is designed for use in Rust applications. Inspired by Jinja2 and Django templates, Tera provides a familiar and expressive syntax for creating dynamic HTML, XML, and other text-based documents. It supports template inheritance, variable interpolation, conditionals, loops, filters, and custom functions, enabling developers to build complex applications with ease.

See the site for more information and to get started.

Features

  • High-performance template rendering
  • Safe and sandboxed execution environment
  • Template inheritance and includes
  • Expressive and familiar syntax
  • Extensible with custom filters and functions
  • Automatic escaping of HTML/XML by default
  • Template caching and auto-reloading for efficient development
  • Built-in support for JSON and other data formats
  • Comprehensive error messages and debugging information

Example

use tera::Tera;

// Create a new Tera instance and add a template from a string
let mut tera = Tera::new();
tera.register_filter("do_nothing", do_nothing_filter);
tera.load_from_glob("examples/basic/templates/**/*")?;
// Prepare the context with some data
let mut context = tera::Context::new();
context.insert("name", "World");

// Render the template with the given context
let rendered = tera.render("hello", &context)?;
assert_eq!(rendered, "Hello, World!");

Getting Started

Add the following to your Cargo.toml file:

[dependencies]
tera = "2"

Then, consult the official documentation and examples to learn more about using Tera in your Rust projects.

Dependencies

~0.1–3MB
~55K SLoC