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) error

Parameters & Attributes

NameTypeDescription
wrio.WriterWriter that receives the rendered output.
dataanyInput 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()}
Go Reference