func httpIndex(w http.ResponseWriter, r *http.Request) {
fmt.Println(r.URL.Path)
t, _ := template.New("main.html").Funcs(template.FuncMap{
"funck": kuai,
}).ParseFiles("main.html", "t.html")
t.Execute(w, map[string]interface{}{
"qq": "aBc",
"cc": "456",
})
}
上面的方法直接展示了编译后的页面,怎么样获取编译后的内容而不是直接展示?
有疑问加站长微信联系(非本文作者)

直接读 w 不久行了
template 渲染的函数签名:Execute(wr io.Writer, data interface{}) error 显然渲染内容可输出到实现 io.Writer 接口的任何地方,比如 os.Stdout,文件,buffer 等地方