lens @ c8e1328164e9ffbd681c3c0e449f1e6b9856b896

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