Например, у меня есть
package main
import "html/template"
import "net/http"
func handler(w http.ResponseWriter, r *http.Request) {
t, _ := template.ParseFiles("header.html", "footer.html")
t.Execute(w, map[string] string {"Title": "My title", "Body": "Hi this is my body"})
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}
В header.html:
Title is {{.Title}}
В footer.html:
Body is {{.Body}}
Когда вы перейдете к http://localhost:8080/
, я вижу только "Title is My title", а не второй файл footer.html. Как загрузить несколько файлов с шаблоном. ParseFiles? Какой самый эффективный способ сделать это?
Спасибо заранее.