blob: b11f9624a8e640836f0cef52fc7fffada179b776 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
package img
import (
"embed"
"fmt"
"html/template"
"io"
)
//go:embed templates/*.html
var TemplateFS embed.FS
var Template *template.Template
type HTMLView[T any] struct {
Title string
Username string
Data T
}
func Render[T any](w io.Writer, page string, view *HTMLView[T]) error {
pageFile := fmt.Sprintf("templates/%s", page)
tmpl, err := template.New("").ParseFS(TemplateFS, "templates/layout.html", pageFile)
if err != nil {
return err
}
return tmpl.ExecuteTemplate(w, page, view)
}
|