Go 带字符串的模板继承

Go 带字符串的模板继承,go,Go,我有几个小的.html文件,我解析如下: template.Must( template.New("test"). ParseFiles( "templates/f1.html", "templates/f2.html", "templates/f3.html", ), ) 这些都是非常小的文件,例如,我想让这些只是字符串,以使我的代码更容易,但我如何做相同类型的模板继承,但字符串?

我有几个小的.html文件,我解析如下:

template.Must(
    template.New("test").
        ParseFiles(
            "templates/f1.html",
            "templates/f2.html",
            "templates/f3.html",
        ),
)
这些都是非常小的文件,例如,我想让这些只是字符串,以使我的代码更容易,但我如何做相同类型的模板继承,但字符串?我看到的只是Parse方法,但它只需要1个字符串:

func (t *Template) Parse(text string) (*Template, error)
我的字符串:

f1 := `Hi there {{template "content" .}}`
f2 := `{{define "content"}}bob {{template "content2" .}}{{end}}`
f3 := `{{define "content2"}}ross{{end}}`
不知道如何让这些“玩”在一起。(这是我正在做的一个简化示例,这些字符串用于多个位置,因此将它们全部合并为1没有意义)。

尝试:

const(
f1=`Hi there{{template“content.”}`
f2=`{{define“content”}bob{{template“content2”。}}{{end}}`
f3=`{{define“content2}}ross{{end}}`
)
func main(){
t:=模板。新(“测试”)
t、 解析(f1)
t、 解析(f2)
t、 解析(f3)
t、 执行(os.Stdout,nil)
}
产生:
你好,鲍勃·罗斯

版本。

尝试:

const(
f1=`Hi there{{template“content.”}`
f2=`{{define“content”}bob{{template“content2”。}}{{end}}`
f3=`{{define“content2}}ross{{end}}`
)
func main(){
t:=模板。新(“测试”)
t、 解析(f1)
t、 解析(f2)
t、 解析(f3)
t、 执行(os.Stdout,nil)
}
产生:
你好,鲍勃·罗斯

版本。

简而言之,检查它是如何实现的:1。创建一个模板
t
,对其进行解析。2.使用
t.New(…)
从第一个创建第二个,对其进行解析。3.等等。简而言之,检查它是如何实现的:1。创建一个模板
t
,对其进行解析。2.使用
t.New(…)
从第一个创建第二个,对其进行解析。3.等等