Crate rocket_dyn_templates::tera

source ·
Expand description

The tera templating engine library, reexported.


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.


  • 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
  • Strict mode for enforcing variable existence
  • Template caching and auto-reloading for efficient development
  • Built-in support for JSON and other data formats
  • Comprehensive error messages and debugging information


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:

tera = "1.0"

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


  • The AST of Tera
  • Re-export some helper fns useful to write filters/fns/tests


  • Helper macro to get real values out of Value while retaining proper errors in filters


  • The struct that holds the context of a template rendering.
  • The Error type
  • Represents a JSON key/value type.
  • Represents a JSON number, whether integer or floating point.
  • This is the parsed equivalent of a template file. It also does some pre-processing to ensure it does as little as possible at runtime Not meant to be used directly.
  • Main point of interaction in this library.


  • The kind of an error (non-exhaustive)
  • Represents any valid JSON value.


  • The filter function type definition
  • The global function type definition
  • The tester function type definition


  • Lookups a dotted path in a json value contrary to the json slash pointer it’s not allowed to begin with a dot
  • Escape HTML following OWASP
  • Interpret a serde_json::Value as an instance of type T.
  • Converts a dotted path to a json pointer one
  • Convert a T into serde_json::Value which is an enum that can represent any valid JSON data.

Type Aliases§

  • Convenient wrapper around std::Result.