wisski-cloud-distillery/internal/dis/component/server/templating/template.go
Tom Wiesing d235ee4e5c
Refactor html templates
This commit entirely refactors the use of html templates. Instead of
inheriting from a shared template, we insert the results into a base
template.
2023-01-23 11:41:20 +01:00

29 lines
758 B
Go

package templating
import (
_ "embed"
"html/template"
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
)
//go:embed "src/footer.html"
var footerHTML string
var footerTemplate = template.Must(template.New("footer.html").Parse(footerHTML))
// GetCustomizable returns either a clone of dflt, or the overriden template with the same name.
func (tpl *Templating) GetCustomizable(dflt *template.Template) *template.Template {
name := dflt.Name()
custom, err := (func() (*template.Template, error) {
data, err := environment.ReadFile(tpl.Environment, tpl.CustomAssetPath(name))
if err != nil {
return nil, err
}
return template.New(name).Parse(string(data))
})()
if err != nil {
return template.Must(dflt.Clone())
}
return custom
}