gonotes/internal/templ/templ.go

31 lines
584 B
Go

package templ
import (
"html/template"
"net/http"
"path/filepath"
"forgejo.gwairfelin.com/max/gonotes/internal/conf"
)
type Ctx map[string]any
func RenderTemplate(w http.ResponseWriter, tmpl string, context any) error {
var err error
files := []string{
filepath.Join("templates", "base.tmpl.html"),
filepath.Join("templates", tmpl),
}
for _, f := range files {
file, err := conf.Templates.Open(f)
if err != nil {
return err
}
file.Close()
}
t, err := template.ParseFS(conf.Templates, files...)
err = t.ExecuteTemplate(w, "base", context)
return err
}