答案 0 :(得分:1)
将其呈现给Stdout的代码
t := template.Must(template.ParseFiles("main.tmpl", "head.tmpl", "foot.tmpl"))
t.Execute(os.Stdout, nil)
main.tmpl:
{{template "header" .}}
<p>main content</p>
{{template "footer" .}}
foot.tmpl:
{{define "footer"}}
<footer>This is the foot</footer>
{{end}}
head.tmpl:
{{define "header"}}
<header>This is the head</header>
{{end}}
这将导致:
<header>This is the head</header>
<p>main content</p>
<footer>This is the foot</footer>
使用html/template将非常相似。