Embed templates and static files
This commit is contained in:
parent
868d2a7bbd
commit
8edd857d22
11 changed files with 31 additions and 17 deletions
|
|
@ -3,7 +3,6 @@ package templ
|
|||
import (
|
||||
"html/template"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"forgejo.gwairfelin.com/max/gonotes/internal/conf"
|
||||
|
|
@ -13,17 +12,19 @@ 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),
|
||||
filepath.Join("templates", "base.tmpl.html"),
|
||||
filepath.Join("templates", tmpl),
|
||||
}
|
||||
|
||||
for _, f := range files {
|
||||
_, err := os.Stat(f)
|
||||
file, err := conf.Templates.Open(f)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
file.Close()
|
||||
}
|
||||
t, err := template.ParseFiles(files...)
|
||||
|
||||
t, err := template.ParseFS(conf.Templates, files...)
|
||||
t.ExecuteTemplate(w, "base", context)
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue