Standard library / html/template
html/template.Template.Execute()
Renders the template using the supplied data and writer; errors may leave partial output. Expected stdout: 'Hello Ada\n'.
Formal Syntax & Structure
go syntaxgo
func (t *Template) Execute(wr io.Writer, data any) errorParameters & Attributes
| Name | Type | Description |
|---|---|---|
| wr | io.Writer | Writer that receives the rendered output. |
| data | any | Input data made available to the template. |
Return Value
error
Parsing or setting error; nil on success.
Working Example
Example Snippetgo
package main
import ( "fmt" "html/template" "os")
func check(e error) { if e != nil { panic(e) }}
func main() { t := template.Must(template.New("greet").Parse("Hello {{.}}")) check(t.Execute(os.Stdout, "Ada")) fmt.Println()}