Documentation
¶
Overview ¶
Package htmx provides helpers for htmx 4: reading htmx request headers, building response headers, and rendering <hx-partial> and out-of-band fragments. See https://four.htmx.org/reference/headers/.
Index ¶
- Constants
- func CurrentURL(r *http.Request) string
- func Is(r *http.Request) bool
- func IsBoosted(r *http.Request) bool
- func IsHistoryRestore(r *http.Request) bool
- func IsPartial(r *http.Request) bool
- func OOB(id, swap string, content template.HTML) template.HTML
- func Partial(target, swap string, content template.HTML) template.HTML
- type Element
- type LocationOptions
- type Response
- func (r *Response) Location(path string) *Response
- func (r *Response) LocationWith(o LocationOptions) *Response
- func (r *Response) PushURL(url string) *Response
- func (r *Response) Redirect(url string) *Response
- func (r *Response) Refresh() *Response
- func (r *Response) ReplaceURL(url string) *Response
- func (r *Response) Reselect(selector string) *Response
- func (r *Response) Reswap(style string) *Response
- func (r *Response) Retarget(selector string) *Response
- func (r *Response) Trigger(event string, detail any) *Response
Constants ¶
const ( HeaderRequest = "HX-Request" HeaderRequestType = "HX-Request-Type" HeaderCurrentURL = "HX-Current-URL" HeaderSource = "HX-Source" HeaderTarget = "HX-Target" HeaderBoosted = "HX-Boosted" HeaderHistoryRestore = "HX-History-Restore-Request" )
Request headers sent by htmx 4.
const ( HeaderTrigger = "HX-Trigger" HeaderLocation = "HX-Location" HeaderRedirect = "HX-Redirect" HeaderRefresh = "HX-Refresh" HeaderPushURL = "HX-Push-Url" HeaderReplaceURL = "HX-Replace-Url" HeaderRetarget = "HX-Retarget" HeaderReswap = "HX-Reswap" HeaderReselect = "HX-Reselect" )
Response headers understood by htmx 4.
Variables ¶
This section is empty.
Functions ¶
func CurrentURL ¶
CurrentURL returns the browser URL when the request started.
func IsHistoryRestore ¶
IsHistoryRestore reports a back/forward navigation re-fetch; it must be answered with a full page (htmx 4 has no local history cache).
func IsPartial ¶
IsPartial reports whether htmx asked for a fragment (targeted swap). Full requests (body swaps, boosted navigation, history restores) need the whole page.
Types ¶
type Element ¶
Element is a "tag#id" reference from HX-Source or HX-Target.
type LocationOptions ¶
type LocationOptions struct {
Path string `json:"path"`
Target string `json:"target,omitempty"`
Swap string `json:"swap,omitempty"`
Select string `json:"select,omitempty"`
Values map[string]any `json:"values,omitempty"`
Header map[string]string `json:"headers,omitempty"`
}
LocationOptions configures an HX-Location navigation.
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
Response sets htmx response headers on w. Methods chain:
htmx.NewResponse(w).Trigger("saved", nil).PushURL("/posts/1")
func NewResponse ¶
func NewResponse(w http.ResponseWriter) *Response
NewResponse returns a Response writing headers to w. It also adds "Vary: HX-Request" so caches keep full pages and fragments apart.
func (*Response) LocationWith ¶
func (r *Response) LocationWith(o LocationOptions) *Response
LocationWith navigates with options.
func (*Response) ReplaceURL ¶
ReplaceURL replaces the current history entry.