I need help.
I need to use "html/template"
's marking ({{.Title}}
, example) in sub-files("article.html"
, example in my text):
// ...
type Page struct {
Test string
}
type News struct {
Page
Title string
}
func main() {
t, _ := template.ParseFiles(filepath+"core.tmpl", filepath+"article.tmpl")
p := &News{
Title: "TITLE",
Page: Page{
Test: "TITLE",
},
}
t.Execute(wr, p)
}
Code in core.tmpl
:
{{template "article"}}
Code in article.tmpl
:
{{define "article"}}
{{.Title}}<br><br>
{{.Page.Test}}
{{end}}