為了清理模板文件夾,我想將常用模板保存在子文件夾中。目前我有以下文件結(jié)構(gòu):main.gotemplates/index.tpl # Main template for the main pagetemplates/includes/head.tpltemplates/includes/footer.tplhead.tpl并且footer.tpl將在被調(diào)用index.tpl,它看起來像這樣:{{ template "head" . }} <h1>My content</h1>{{ template "footer" .}}此外,文件使用template.ParseGlob(). 這是摘錄自main.go:var views = template.Must(template.ParseGlob("src/templates/**/*"))func Render(rw http.ResponseWriter, temp string, data interface{}) { err := views.ExecuteTemplate(rw, temp, data) if err != nil { http.Error(rw, err.Error(), http.StatusInternalServerError) }}func Index(rw http.ResponseWriter, req *http.Request) { Render(rw, "index.tpl", nil)}每次打開瀏覽器時(shí),都會(huì)收到以下錯(cuò)誤消息:html/template: "index.tpl" is undefined.是否有可能index.tpl被這種 glob 模式忽略?我發(fā)現(xiàn)了這個(gè)類似的問題,但答案只是一個(gè)解決方法。
- 2 回答
- 0 關(guān)注
- 199 瀏覽
添加回答
舉報(bào)
0/150
提交
取消