Golang html/template.Template.AddParseTree function example
package html/template
AddParseTree creates a new template with the name(1st parameter) and parse tree(2nd parameter and associates it with t.
It returns an error if t has already been executed.
Golang html/template.Template.AddParseTree function usage example
err := filepath.Walk(templateDir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() {
return nil
}
rel, err := filepath.Rel(templateDir, path)
if err != nil {
return err
}
t := template.Must(template.ParseFiles(path))
log.Printf(" %v\n", rel)
templates = template.Must(templates.AddParseTree(rel, t.Tree)) // <--- here
return nil
})
if err != nil {
log.Fatal("Unable to load templates.")
}
References :
https://github.com/bklimt/weather/blob/master/cmd/weather/templates.go
Advertisement
Something interesting
Tutorials
+22.9k Golang : Gorilla mux routing example
+12.1k Golang : Save webcamera frames to video file
+30k Golang : Get time.Duration in year, month, week or day
+12.3k Golang : List running EC2 instances and descriptions
+5.2k JavaScript/JQuery : Redirect page examples
+9.9k Golang : Turn string or text file into slice example
+17.8k Golang : Iterate linked list example
+13.7k Golang : Activate web camera and broadcast out base64 encoded images
+16.5k Golang : Execute terminal command to remote machine example
+10.8k Android Studio : Checkbox for user to select options example
+6.4k Golang : How to search a list of records or data structures
+9.2k nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)