Templates tmpl.Execute和子文件golang
我需要帮助。 我需要在子文件(Templates tmpl.Execute和子文件golang,templates,go,Templates,Go,我需要帮助。 我需要在子文件(“article.html”,文本中的示例)中使用“html/template”的标记({.Title}},示例): core.tmpl中的代码: {{template "article"}} {{define "article"}} {{.Title}}<br><br> {{.Page.Test}} {{end}} article.tmpl中的代码: {{template "article"}} {{define "article"}
“article.html”
,文本中的示例)中使用“html/template”
的标记({.Title}}
,示例):
core.tmpl
中的代码:
{{template "article"}}
{{define "article"}}
{{.Title}}<br><br>
{{.Page.Test}}
{{end}}
article.tmpl
中的代码:
{{template "article"}}
{{define "article"}}
{{.Title}}<br><br>
{{.Page.Test}}
{{end}}
{{定义“文章”}
{{.Title}}
{{.Page.Test}
{{end}
在核心.tmpl中,您必须使用
{{template "article" .}}
如果未在末尾指定
,则将使用nil
数据执行模板。指定
将
的值传递给调用的模板
引用程序包文档中的操作部分:
{{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.