Tera Hello World



examples/tera/hello-world/Cargo.toml
[package]
name = "hello-world"
version = "0.1.0"
edition = "2021"

[dependencies]
tera = "1.20.0"

examples/tera/hello-world/src/main.rs
use tera::Context;
use tera::Tera;

fn main() {
    let tera = Tera::new("templates/*.html").unwrap();

    let mut context = Context::new();
    context.insert("name", "World");

    let result = tera.render("hello.html", &context).unwrap();
    assert_eq!(result, "Hello, World!");
    println!("{result}");
}

examples/tera/hello-world/templates/hello.html
Hello, {{name}}!

$ tree
.
├── Cargo.lock
├── Cargo.toml
├── src
│   └── main.rs
└── templates
    └── hello.html