Is there a way to make the template order irrelevant.
Here's my code:
var overallTemplates = []string{
"templates/analytics.html",
"templates/header.html",
"templates/footer.html"}
func HomeHandler(w http.ResponseWriter, r *http.Request) {
render(w,
append([]string{"templates/home.html"}, overallTemplates...),
nil)
}
func render(w http.ResponseWriter, files []string, data interface{}) {
tmpl := template.Must(template.ParseFiles(files...))
err := tmpl.Execute(w, data)
if err != nil {
fmt.Printf("Couldn't load template: %v
", err)
}
}
It works but if I change the order of overallTemplates
to:
var overallTemplates = []string{
"templates/header.html",
"templates/footer.html",
"templates/analytics.html"}
I get a blank page because analytics.html content is something like {{define "analytics"}}...{{end}}
and it's called by footer.html
like {{define "footer"}}{{template "analytics"}} ...{{end}}