Standard library / html/template

html/template.Template.Clone()

Copies the template namespace so definitions can be added independently. Clone HTML templates before execution. Expected stdout: 'true true\n'.

Formal Syntax & Structure

go syntaxgo
func (t *Template) Clone() (*Template, error)

Return Value

(*Template, error)

Copies the template namespace so definitions can be added independently.

Working Example

Example Snippetgo
package main
import (  "fmt"  "html/template")
func check(e error) {  if e != nil {    panic(e)  }}
func main() {  t := template.Must(template.New("greet").Parse("Hello {{.}}"))  c, e := t.Clone()  check(e)  _, e = c.New("extra").Parse("new")  check(e)  fmt.Println(t.Lookup("extra") == nil, c.Lookup("extra") != nil)}
Go Reference