···11+package pages
22+33+import (
44+ "fmt"
55+ "net/http"
66+)
77+88+// Notice performs a hx-oob-swap to replace the content of an element with a message.
99+// Pass the id of the element and the message to display.
1010+func (s *Pages) Notice(w http.ResponseWriter, id, msg string) {
1111+ html := fmt.Sprintf(`<span id="%s" hx-swap-oob="innerHTML">%s</span>`, id, msg)
1212+1313+ w.Header().Set("Content-Type", "text/html")
1414+ w.WriteHeader(http.StatusOK)
1515+ w.Write([]byte(html))
1616+}
1717+1818+// HxRedirect is a full page reload with a new location.
1919+func (s *Pages) HxRedirect(w http.ResponseWriter, location string) {
2020+ w.Header().Set("HX-Redirect", location)
2121+ w.WriteHeader(http.StatusOK)
2222+}
2323+2424+// HxLocation is an SPA-style navigation to a new location.
2525+func (s *Pages) HxLocation(w http.ResponseWriter, location string) {
2626+ w.Header().Set("HX-Location", location)
2727+ w.WriteHeader(http.StatusOK)
2828+}