lens @ 55448bc974f71f83e6a6c6d70afe9cfc63d275f4

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