例如.go,我有
package main
import "html/template"
import "net/http"
func handler(w http.ResponseWriter, r *http.Request) {
t, _ := template.ParseFiles("header.html", "footer.html")
t.Execute(w, map[string] string {"Title": "My title", "Body": "Hi this is my body"})
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}
在 header.html 中:
Title is {{.Title}}
在页脚.html 中:
Body is {{.Body}}
转到时http://localhost:8080/
,我只看到“标题是我的标题”,而不是第二个文件 footer.html。如何使用 template.ParseFiles 加载多个文件?最有效的方法是什么?
提前致谢。