29 lines
550 B
Go
29 lines
550 B
Go
package templ
|
|
|
|
import (
|
|
"html/template"
|
|
"net/http"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"forgejo.gwairfelin.com/max/gonotes/internal/conf"
|
|
)
|
|
|
|
type Ctx map[string]any
|
|
|
|
func RenderTemplate(w http.ResponseWriter, tmpl string, context any) error {
|
|
files := []string{
|
|
filepath.Join(conf.Conf.Templates.Dir, conf.BaseTemplate),
|
|
filepath.Join(conf.Conf.Templates.Dir, tmpl),
|
|
}
|
|
|
|
for _, f := range files {
|
|
_, err := os.Stat(f)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
t, err := template.ParseFiles(files...)
|
|
t.ExecuteTemplate(w, "base", context)
|
|
return err
|
|
}
|