Add templ package to handle rendering of templates

This commit is contained in:
Maximilian Friedersdorff 2025-01-28 21:27:18 +00:00
parent e6b5ea3921
commit e7e420cd47
6 changed files with 25 additions and 14 deletions

19
internal/templ/templ.go Normal file
View file

@ -0,0 +1,19 @@
package templ
import (
"html/template"
"net/http"
"path/filepath"
"gitea.gwairfelin.com/max/gonotes/internal/conf"
)
func RenderTemplate(w http.ResponseWriter, tmpl string, context any) error {
files := []string{
filepath.Join(conf.Conf.TemplatesDir, conf.Conf.BaseTemplate),
filepath.Join(conf.Conf.TemplatesDir, tmpl),
}
t, err := template.ParseFiles(files...)
t.ExecuteTemplate(w, "base", context)
return err
}