2 回答
TA贡献1810条经验 获得超5个赞
你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贡献1788条经验 获得超4个赞
更新:所以我只需要创建一个页眉和页脚模板:
{{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 关注
- 140 浏览
添加回答
举报