Crate tera

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

Example

use tera::Tera;

// Create a new Tera instance and add a template from a string
let mut tera = Tera::new("templates/**/*").unwrap();
tera.add_raw_template("hello", "Hello, {{ name }}!").unwrap();
// 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).unwrap();
assert_eq!(rendered, "Hello, World!");

Getting Started

Add the following to your Cargo.toml file:

[dependencies]
tera = "1.0"

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

Modules

Macros