Add templ package to handle rendering of templates
This commit is contained in:
parent
e6b5ea3921
commit
e7e420cd47
6 changed files with 25 additions and 14 deletions
19
internal/templ/templ.go
Normal file
19
internal/templ/templ.go
Normal 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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue