Skip to main content

Crate trillium_tera

Crate trillium_tera 

Source
Expand description

§this crate provides the tera templating language for trillium

See the tera site for more information on the tera template language.

This crate tracks tera 2, and enables tera’s fast feature by default. The preserve_order and unicode tera features are also available as passthroughs.

use trillium::Conn;
use trillium_tera::{Tera, TeraConnExt, TeraHandler};
use trillium_testing::TestServer;

let mut tera = Tera::default();
tera.add_raw_template("hello.html", "hello {{name}} from {{render_engine}}")?;

let handler = (
    TeraHandler::new(tera),
    |conn: Conn| async move { conn.assign("render_engine", "tera") },
    |conn: Conn| async move { conn.assign("name", "trillium").render("hello.html") },
);

let app = TestServer::new(handler).await;
app.get("/")
    .await
    .assert_ok()
    .assert_body("hello trillium from tera")
    .assert_header("content-type", "text/html");

Structs§

Context
The struct that holds the context of a template rendering.
Error
The Error struct for Tera.
Tera
Main point of interaction in this library.
TeraHandler
A trillium handler for the Tera template engine

Traits§

Filter
The filter function type definition
Function
The function function type definition
TeraConnExt
Extends trillium::Conn with tera template-rendering functionality.
Test
The test function type definition

Type Aliases§

TeraResult
A custom Result type for this library