Go html/template-style rendering in Rust.
go_html_template is a Rust crate that mirrors major Go html/template workflows. It supports template syntax, pipelines, context-aware escaping, and unsafe URL scheme blocking while keeping a familiar API shape.
Go-like Template API
Use Template::new(...).parse(...).execute(...) with define/template/range/with/pipeline features.
Context-aware Escaping
Applies context-aware escaping for HTML text, attributes, URL attributes, and script/style contexts, and blocks unsafe javascript: URLs.
web-rust Mode
With the web-rust feature, parse_files/parse_glob/parse_fs are disabled so in-memory template loading can be enforced.
Setup and Basic Usage
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