2 回答

TA貢獻1810條經(jīng)驗 獲得超5個贊
你contact.html不會“渲染”任何東西。它只是定義body模板,但不包括它(執(zhí)行它)。
要執(zhí)行模板(在模板內),您可以使用{{template}}操作。要定義和執(zhí)行模板,您可以使用{{block}}操作。
模板操作:
{{template "name"}}
The template with the specified name is executed with nil data.
{{template "name" pipeline}}
The template with the specified name is executed with dot set
to the value of the pipeline.
{{block "name" pipeline}} T1 {{end}}
A block is shorthand for defining a template
{{define "name"}} T1 {{end}}
and then executing it in place
{{template "name" pipeline}}
The typical use is to define a set of root templates that are
then customized by redefining the block templates within.
如果您的目標是在所有頁面中都有一個“固定”的頁眉和頁腳,那么您必須重新構建您的模板。在某處定義了一個header和模板,頁面應該將它們作為第一個和最后一個元素包含在內。footer請參閱如何使用結構或變量值的字段作為模板名稱?

TA貢獻1788條經(jīng)驗 獲得超4個贊
更新:所以我只需要創(chuàng)建一個頁眉和頁腳模板:
{{template "header" .}}
<h1>Contact us page</h1>
<p>
Your name is...
</p>
{{template "footer" .}}
{{define "header"}}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>{{.Title}}</title>
<meta name="description" content="{{.Description}}">
<link rel="canonical" href="{{.Canonical}}" />
</head>
<body>
{{end}}
{{define "footer"}}
</body>
</html>
{{end}}
它工作得很好
- 2 回答
- 0 關注
- 156 瀏覽
添加回答
舉報