Sibert
(Sibert)
1
This works
tpl.ExecuteTemplate(w, "index.html", data)
But sending a parameter this does not work. How can I get this to work?
page := template.HTML("index.html")
tpl.ExecuteTemplate(w, page, data)
./main.go:84:27: cannot use page (type func(http.ResponseWriter, *http.Request)) as type string in argument to tpl.ExecuteTemplate
lutzhorn
(Lutz Horn)
2
What happens? Do you get an error?
1 Like
Sibert
(Sibert)
3
I think I found the solution. It was maybe variable scope
path := strings.Trim(r.URL.Path, "/")
var page string <--- variable scope?
switch path {
case "":
page = "index.html"
fmt.Println(page, list)
default:
page = path + ".html"
fmt.Println(page, list)
}
err = tpl.ExecuteTemplate(w, page, list)
system
(system)
Closed
4
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.