Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.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
Google app engine 将html模板组合成一个in-GAE GO基本模板,这样该结构就只有一个通用的html/css结构_Google App Engine_Parsing_Templates_Go - Fatal编程技术网

Google app engine 将html模板组合成一个in-GAE GO基本模板,这样该结构就只有一个通用的html/css结构

Google app engine 将html模板组合成一个in-GAE GO基本模板,这样该结构就只有一个通用的html/css结构,google-app-engine,parsing,templates,go,Google App Engine,Parsing,Templates,Go,在本例中,我有一个main.html模板 <!DOCTYPE html> <html> <head> <title>Backend</title> <style> html, body {height:100%} </style> </head> <body> <table border="1" width="100%" height="100%">

在本例中,我有一个main.html模板

<!DOCTYPE html>
<html>
<head>
  <title>Backend</title>
  <style>
    html, body {height:100%}
  </style>
</head>
<body>
  <table border="1" width="100%" height="100%">
    <tr>
      <td colspan="2" class="td-header">
        <h1>Google GO</h1>
      </td>
    </tr>
    <tr>
      <td class="td-right-content">
       {{<parsed template from children>}}
      </td>
    </tr>
    <tr>
      <td colspan="2" class="td-header">
        <h1>Footer</h1>
      </td>
    </tr>
  </table>
</body>
</html>

后端
html,正文{高度:100%}
谷歌围棋
{{}}
页脚
孩子的部分将填补这个空白

{{}


名称
描述
{{range.}}
{{.Name}
{{.Description}
{{end}
在子部件的代码中解析后。 我这样做是为了消除多余的html和css,并轻松管理设计。
谢谢大家

A
Template
对象包含一个顶级模板(此处为父模板),该模板可能引用同一对象中关联的其他模板。模板具有用于引用的名称

这可能很棘手,因为当您使用
ParseFiles
函数创建新对象时,每个模板都使用文件的基本名称命名(而且似乎不可能更改该名称)。如果给定的main有多个可能的子文件,这可能是不切实际的,因为您通常不希望给它们相同的名称

解决方案是手动将文件读取为字符串,然后将其添加到显式命名的模板中(IMO有点麻烦,但您可以接受它)

(我跳过了示例中的所有错误处理)

然后,您可以在父页面中使用
{{template}
指令:

{{template "content" .}}
(或任何管道,而不是
,它指的是提供给
主\u temp
的整个对象)

有关更多详细信息,请参阅

main_temp,_ := template.ParseFiles("main.html")

cont_s,_ := ioutil.ReadFile("content1.html")

// add a new associated template to main 
cont_temp,_ := main_temp.New("content").Parse(string(cont_s))

g := Content{"Hi"}
main_temp.Execute(os.Stdout, &g)
{{template "content" .}}