Templates 变量在局部视图中不可见
为什么我的Templates 变量在局部视图中不可见,templates,go,Templates,Go,为什么我的页面对象的标题属性未填充在标题模板中 这是我的小围棋程序 package main import ( "html/template" "os" ) type Page struct { Title string Body string } func main() { f, _ := os.Create("index.html") defer f.Close() page := Page{"I'm the title", "And I'm the b
页面
对象的标题
属性未填充在标题模板中
这是我的小围棋程序
package main
import (
"html/template"
"os"
)
type Page struct {
Title string
Body string
}
func main() {
f, _ := os.Create("index.html")
defer f.Close()
page := Page{"I'm the title", "And I'm the body"}
t := template.New("post.html")
t = template.Must(t.ParseGlob("templates/*html"))
t.Execute(f, page)
}
以下是templates/post.html文件:
{{template "header.html"}}
<article>
{{.Body}}
</article>
{{template "footer.html"}}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>{{.Title}}</title>
</head>
<body>
<footer>
© 2015
</footer>
</body>
</html>
{{template”header.html}
{{template“header.html”}
表单不传递任何数据
试试{template”header.html.}}
有关详细信息,请参阅的“操作”部分。{{template“header.html”}
表单不传递任何数据
试试{template”header.html.}}
有关详细信息,请参阅的“操作”部分。{{template“header.html”}
表单不传递任何数据
试试{template”header.html.}}
有关详细信息,请参阅的“操作”部分。{{template“header.html”}
表单不传递任何数据
试试{template”header.html.}}
有关详细信息,请参阅的“操作”部分。可能重复的可能重复的可能重复的可能重复的可能重复的