Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Templates 变量在局部视图中不可见_Templates_Go - Fatal编程技术网

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>
&copy; 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.}}

有关详细信息,请参阅的“操作”部分。

可能重复的可能重复的可能重复的可能重复的可能重复的