Tera Hello World
- Context
- render
[package]
name = "hello-world"
version = "0.1.0"
edition = "2024"
[dependencies]
tera = "1.20.0"
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}");
}
Hello, {{name}}!
$ tree
.
├── Cargo.lock
├── Cargo.toml
├── src
│ └── main.rs
└── templates
└── hello.html