aboutsummaryrefslogtreecommitdiff
path: root/tmpl.go
diff options
context:
space:
mode:
Diffstat (limited to 'tmpl.go')
-rw-r--r--tmpl.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/tmpl.go b/tmpl.go
new file mode 100644
index 0000000..b11f962
--- /dev/null
+++ b/tmpl.go
@@ -0,0 +1,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)
+}