【发布时间】:2016-11-21 06:51:58
【问题描述】:
问题出在:每个页面的content 部分有几个articles,我想在每篇文章下方插入一个likebar 模板。
所以base.tmpl 就像:
<html>
<head>
{{template "head.tmpl" .}}
</head>
<body>
{{template "content.tmpl" .}}
</body>
</html>
在article.tmpl 我想要:
{{define "content"}}
<div>article 1
{{template "likebar.tmpl" .}}
</div>
<div>article 2
{{template "likebar.tmpl" .}}
</div>
... //these divs are generated dynamically
{{end}}
如何使用html/template 实现这一目标?
我试图在base.tmpl 中插入一个{{template "iconbar" .}},然后在{{define "content" 中嵌套{{template "likebar.tmpl" .}},但它失败了:
模板文件错误:html/template:base.tmpl:122:12:没有这样的模板 "likebar.tmpl"
【问题讨论】:
标签: go go-templates