Use the askama crate to compile templates at build time and render them with Rust structs. Add askama and askama_derive to your dependencies, define a struct matching your template data, and implement the Template trait using the #[template] attribute. Then, call .render() on your struct instance to get the final string.
use askama::Template;
#[derive(Template)]
#[template(path = "hello.html")]
struct Greeting<'a> {
name: &'a str,
}
fn main() {
let greeting = Greeting { name: "World" };
println!("{}", greeting.render().unwrap());
}
Create a hello.html file in your templates directory with content like Hello, {{ name }}!.