Dynamic FAQ page template

This commit is contained in:
2024-08-01 10:11:56 -04:00
parent 13bf91ba7d
commit 920e7972af
3 changed files with 37 additions and 5 deletions

View File

@@ -18,3 +18,31 @@ func StaticTemplate(templatePath string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { tpl.Execute(w, nil) }
}
func FAQ(templatePath string) http.HandlerFunc {
questions := []struct {
Question string
Answer string
}{
{
Question: "Is this a real website?",
Answer: "No.",
},
{
Question: "I Can Has Cheezburger?",
Answer: "No.",
},
}
tpl := views.Must(views.FromFS(templates.FS, templatePath))
var testWriter strings.Builder
err := tpl.ExecuteWriter(&testWriter, nil)
if err != nil {
panic(err)
}
return func(w http.ResponseWriter, r *http.Request) {
tpl.Execute(w, questions)
}
}