#template #template-string #sql #rio #filter #variables

yanked rio_templates

Template engine for Rio, based on Tera

1 unstable release

0.1.0 Dec 11, 2023

#8 in #rio

MIT license

505KB
13K SLoC

Rio Templates

Rio Templates is the template engine that powers Rio. The project is a fork of Tera, which is itself inspired by Jinja2 and the Django template language.


lib.rs:

Rio Templates

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

This crate provides an implementation of the Rio template engine, which is designed for use in Rust applications. Inspired by Jinja2 and Django templates, Rio templates provide 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.

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 rio_templates::Engine;

// Create a new Engine instance and add a template from a string
let mut engine = Engine::new("templates/**/*").unwrap();
engine.add_raw_template("hello", "Hello, {{ name }}!").unwrap();
// Prepare the context with some data
let mut context = rio_templates::Context::new();
context.insert("name", "World");

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

Getting Started

Add the following to your Cargo.toml file:

[dependencies]
rio_templates = "1.0"

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

Dependencies

~9–18MB
~201K SLoC