Standard library / text/template

text/template.Template.Parse()

Parses trusted template source and associates definitions. A syntax error is returned. Expected stdout: 'Hello Ada\n'.

Formal Syntax & Structure

go syntaxgo
func (t *Template) Parse(text string) (*Template, error)

Parameters & Attributes

NameTypeDescription
textstringTemplate source text, authored by a trusted developer.

Return Value

(*Template, error)

Parses trusted template source and associates definitions.

Working Example

Example Snippetgo
package main
import (  "fmt"  "os"  "text/template")
func check(e error) {  if e != nil {    panic(e)  }}
func main() {  t, e := template.New("greet").Parse("Hello {{.}}")  check(e)  check(t.Execute(os.Stdout, "Ada"))  fmt.Println()}
Go Reference