oef/util/template/html.go
2019-11-04 15:00:46 +01:00

29 lines
559 B
Go

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
}