Standard library / html/template

html/template.Template.AddParseTree()

Associates a previously parsed syntax tree with a name. Do this before executing HTML templates. Expected stdout: 'Hello Ada\n'.

Formal Syntax & Structure

go syntaxgo
func (t *Template) AddParseTree(name string, tree *parse.Tree) (*Template, error)

Parameters & Attributes

NameTypeDescription
namestringName of the template.
tree*parse.TreeParsed template syntax tree.

Return Value

(*Template, error)

Associates a previously parsed syntax tree with a name.

Working Example

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