import "os"
import "html/template"
...
t, _ := template.ParseFiles("login.html")
t.Execute(os.Stdout, data)
...
login.html:
{{ template "header.html" . }}
<form ....>...</form>
{{ template "footer.html" . }}
没有输出,没有错误。Golang:使用{{template“partial.html”的先决条件是什么? }}
如果我删除这两行{{template“...”。 }},我可以看到该部分是输出。
需要什么才能使{{template“...”。 }}工作还是我完全误解了html /模板?
它*看起来像*你可能假设'模板'行动可以采取一个文件名;它不能。它指的是已经解析过的命名模板(通过'template.Parse ...','someOtherTemplate.Parse ...'或者通过解析模板的'define'动作)。请参阅'text/template'包文档的[“关联模板”](https://golang.org/pkg/text/template/#hdr-Associated_templates)部分。 –
@DaveC此链接http://gohugo.io/templates/go-templates/似乎暗示它可以;但是它来自谷歌搜索,我不知道这是否是hugo添加的一些语法suger。 – Shawn
可能重复[golang模板 - 如何呈现模板?](http://stackoverflow.com/questions/19546896/golang-template-how-to-render-templates) – Shawn