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
- 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
Example
use Tera;
// Create a new Tera instance and add a template from a string
let mut tera = new.unwrap;
tera.add_raw_template.unwrap;
// Prepare the context with some data
let mut context = new;
context.insert;
// Render the template with the given context
let rendered = tera.render.unwrap;
assert_eq!;
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
- helpers Re-export some helper fns useful to write filters/fns/tests
Macros
- try_get_value Helper macro to get real values out of Value while retaining proper errors in filters