Standard library / text/template

text/template.Template.New()

Creates a named template associated with the receiver. Expected stdout: 'Hello Ada\n'.

Formal Syntax & Structure

go syntaxgo
func (t *Template) New(name string) *Template

Parameters & Attributes

NameTypeDescription
namestringName of the template.

Return Value

*Template

Creates a named template associated with the receiver.

Working Example

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