Golang html/template.Template.ExecuteTemplate function examples
package html/template
ExecuteTemplate applies the template associated with t that has the given name to the specified data object and writes the output to wr(1st parameter). If an error occurs executing the template or writing its output, execution stops, but partial results may already have been written to the output writer. A template may be executed safely in parallel.
Golang html/template.Template.ExecuteTemplate function usage examples
Example 1:
var ie template.HTML = `<!--[if lt IE 9]>
<script src="js/html5shiv.min.js"></script>
<script src="js/respond.min.js"></script>
<![endif]-->`
func rootHandler(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
http.NotFound(w, r)
return
}
title := "Home"
templates.ExecuteTemplate(w, "header.html", &info{title, ie})
templates.ExecuteTemplate(w, "index.html", nil)
templates.ExecuteTemplate(w, "footer.html", title)
}
Example 2:
var context interface{}
var buf *bytes.Buffer = &bytes.Buffer{}
temp.ExecuteTemplate(buf, "base", context)
References :
https://github.com/aclissold/andrewclissold.appspot.com/blob/master/app.go
http://golang.org/pkg/html/template/#Template.ExecuteTemplate
Advertisement
Something interesting
Tutorials
+36.5k Golang : Validate IP address
+20.2k Golang : Convert seconds to human readable time format example
+7.4k Golang : Check to see if *File is a file or directory
+5.2k Golang : Customize scanner.Scanner to treat dash as part of identifier
+4.7k Adding Skype actions such as call and chat into web page examples
+11.5k Use systeminfo to find out installed Windows Hotfix(s) or updates
+11.1k Golang : How to determine a prime number?
+13.7k Golang : Image to ASCII art example
+19.2k Golang : Execute shell command
+21.8k Golang : How to reverse slice or array elements order
+16.5k Golang : Check if a string contains multiple sub-strings in []string?