Golang html/template.Template type examples

package html/template

Template is a specialized Template from "text/template" that produces a safe HTML document fragment.

Golang html/template.Template type usage examples

Example 1:

 var Templates = make(map[string]*template.Template)

 func registerTemplate(name string, t *template.Template) {
 Templates[name] = t
 }

Example 2:

 var templates *template.Template
 templates = template.Must(template.ParseFiles(cfg.template))

Example 3:

 var defaultTemplate string = '<!DOCTYPE html><html lang="en"><head><title>{{ .ClusterName }}</title></head><body ..........' // fill up here
 var tmpl *template.Template
 var err error
 tmpl, err = template.New("base").Parse(defaultTemplate) 

References :

https://github.com/AcalephStorage/consul-alerts/blob/master/notifier/email-notifier.go

https://github.com/borgenk/qdo/blob/master/http/server.go

http://golang.org/pkg/html/template/#Template

Advertisement