Use Tera filters (length)


this is a simple example using the length filter:


examples/rocket/use-tera-filter/templates/index.html.tera
Hello <b>{{ text }}!</b> length: <b>{{ text | length }}</b>

examples/rocket/use-tera-filter/src/main.rs
#[macro_use]
extern crate rocket;

use rocket_dyn_templates::{context, Template};

#[get("/")]
fn index() -> Template {
    let text = "Rocket with Tera";
    Template::render(
        "index",
        context! {
            text
        },
    )
}

#[launch]
fn rocket() -> _ {
    rocket::build()
        .mount("/", routes![index])
        .attach(Template::fairing())
}

#[cfg(test)]
mod tests;

examples/rocket/use-tera-filter/src/tests.rs
use rocket::http::Status;
use rocket::local::blocking::Client;

#[test]
fn hello_world() {
    let client = Client::tracked(super::rocket()).unwrap();
    let response = client.get("/").dispatch();

    assert_eq!(response.status(), Status::Ok);
    assert_eq!(
        response.headers().get_one("Content-Type").unwrap(),
        "text/html; charset=utf-8"
    );
    assert_eq!(
        response.into_string(),
        Some("Hello <b>Rocket with Tera!</b> length: <b>16</b>".into())
    );
}

examples/rocket/use-tera-filter/Rocket.toml
[debug]
port=8001