package main import ( "html/template" "os" ) func main() { t, err := template.New("test").Parse("Hello, {{.Name}}!") if err != nil { panic(err) } data := struct{ Name string }{ Name: "World", } err = t.Execute(os.Stdout, data) if err != nil { panic(err) } }
package main import ( "html/template" "os" ) func main() { t, err := template.ParseFiles("template.html") if err != nil { panic(err) } data := struct{ Name string }{ Name: "World", } err = t.Execute(os.Stdout, data) if err != nil { panic(err) } }In this example, a template is read from a file "template.html" by calling "ParseFiles" on a new instance of "template.Template". Then, a data struct is defined with a single field "Name" and is set to "World". The data is passed to the template by calling the "Execute" method on the parsed template. The result is written to the standard output. Package library: html/template.