This repository has been archived on 2025-03-01. You can view files and clone it, but cannot push or open issues or pull requests.
trantor/template.go

28 lines
677 B
Go
Raw Normal View History

package main
import (
"html/template"
"net/http"
)
2012-08-15 15:11:52 +02:00
const (
TEMPLATE_DIR = "templates/"
)
func loadTemplate(w http.ResponseWriter, tmpl string, data interface{}) {
// TODO: when finish devel conver to global:
2012-08-15 15:11:52 +02:00
var templates = template.Must(template.ParseFiles(TEMPLATE_DIR + "header.html",
TEMPLATE_DIR + "footer.html",
TEMPLATE_DIR + "index.html",
TEMPLATE_DIR + "about.html",
TEMPLATE_DIR + "book.html",
TEMPLATE_DIR + "search.html",
TEMPLATE_DIR + "upload.html"))
2012-08-15 12:00:44 +02:00
err := templates.ExecuteTemplate(w, tmpl+".html", data)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}