oef/util/template/html.go

30 lines
559 B
Go
Raw Normal View History

2019-11-04 15:00:46 +01:00
package template
import (
"html/template"
"io/ioutil"
)
func LoadHTMLTemplate(filename string, funcMap ...template.FuncMap) (*template.Template, error) {
var (
tpl *template.Template
err error
)
content, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
}
if len(funcMap) > 0 {
tpl, err = template.New(filename).Funcs(funcMap[0]).Parse(string(content))
if err != nil {
return nil, err
}
} else {
tpl, err = template.New(filename).Parse(string(content))
if err != nil {
return nil, err
}
}
return tpl, nil
}