Dynamic FAQ page template
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user