Go html/template-style rendering in Rust.
go_html_template is a Rust crate for familiar Go html/template workflows. It supports template syntax, pipelines, contextual escaping, and unsafe URL-scheme blocking while keeping the API shape recognizable.
Go-like Template API
Use Template::new(...).parse(...).execute(...) with define, template, range, with, and pipeline features.
Context-aware Escaping
Applies contextual escaping to HTML text, attributes, URL attributes, and script/style contexts, while blocking unsafe javascript: URLs.
web-rust Mode
With the web-rust feature, parse_files, parse_glob, and parse_fs are disabled so loading templates in memory can be enforced.
Set up and run a first template
Add the crate, then verify a minimal parse + execute_to_string flow. In web-rust environments, use in-memory template strings instead of file-loading APIs.
Install
cargo add go_html_template
Rust Example
use go_html_template::{Template, Value};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let tpl = Template::new("page")
.parse(r#"<h1>{{.Title}}</h1>\n<p>{{.Body | safe_html}}</p>"#)?;
let out = tpl.execute_to_string(&serde_json::json!({
"Title": "go_html_template",
"Body": "<em>trusted</em>"
}))?;
println!("{out}");
Ok(())
}
Compatibility Status
go_html_template currently implements core workflows while continuing to close compatibility gaps . It is not yet a strict 1:1 compatibility target with Go html/template, so verify behavior in your production templates.
Previous
OSS ListNext
README / Full Specs