I'm trying to figure out how to go about loading multiple templates in Go when a lot of them have a similar....base, you could say?
Currently, I've got the following two templates I'm loading in a sample application I'm working on:
homeTemplate, err = template.ParseFiles(
"views/layout/base.gohtml",
"views/layout/menu.html",
"views/layout/footer.gohtml",
"views/home.gohtml")
if err != nil {
panic(err)
}
contactTemplate, err = template.ParseFiles(
"views/layout/base.gohtml",
"views/layout/menu.html",
"views/layout/footer.gohtml",
"views/contact.gohtml")
if err != nil {
panic(err)
}
My question is the following:
Is there a way to set this up in such a way that I can store the first three entries in each list of templates in a variable and then just append the final inclusion at the end so I can shorten the amount of code and simplify things?
Am I tackling this whole thing wrong? I read somewhere about using a setup that incorporated a template["name"]
syntax and then rendering from that, maybe I just need to load the base templates before the rest of this stuff, since they're more of less for layout stuff, and they probably don't need to be part of the above variables?