我有这个变量,我想知道是否可以执行多个模板
如果我无法使用此变量执行操作,该怎么办?
var (
templates = template.Must(template.ParseGlob("web/Pages/*"))
)
提前致谢
最佳答案
您可以使用{{ template "name" }}
操作将模板包括在其他模板中。
假设您有a.html
文件:
<p>this is A</p>
那么您可以将其包含在
b.html
中,如下所示:{{ template "a.html" }}
<p>this is B</p>
然后,如果您运行
templates.ExecuteTemplate(os.Stdout, "b.html", nil)
,您将获得:<p>this is A</p>
<p>this is B</p>
有关更多实例,请参见操场链接:https://play.golang.com/p/W0whRWlX119
关于go - 在go中执行多个模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61477173/