2 回答

TA貢獻1873條經驗 獲得超9個贊
你的contact.html
不“渲染”任何東西。它僅定義body
模板,但不包含它(執行它)。
要執行模板(模板內),您可以使用該{{template}}
操作。要定義和執行模板,您可以使用該{{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貢獻1829條經驗 獲得超7個贊
更新:所以我不得不創建一個頁眉和頁腳模板:
{{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 關注
- 194 瀏覽
添加回答
舉報