Documentation
¶
Index ¶
- Constants
- Variables
- func CurrentURL(c *xun.Context) string
- func HandleFunc() xun.HandleFunc
- func IsBoosted(c *xun.Context) bool
- func IsHistoryRestore(c *xun.Context) bool
- func IsHxRequest(c *xun.Context) bool
- func New() xun.Interceptor
- func Prompt(c *xun.Context) string
- func Target(c *xun.Context) string
- func Trigger(c *xun.Context) string
- func TriggerName(c *xun.Context) string
- func WriteHeader(c *xun.Context, key string, value any)
- func WriteLocation(c *xun.Context, location HxHeader[string])
- func WritePushUrl(c *xun.Context)
- func WritePushUrlTo(c *xun.Context, url string)
- func WriteRedirect(c *xun.Context, url string)
- func WriteRefresh(c *xun.Context)
- func WriteReplaceUrl(c *xun.Context)
- func WriteReplaceUrlTo(c *xun.Context, url string)
- func WriteReselect(c *xun.Context, selector string)
- func WriteReswap(c *xun.Context, strategy string)
- func WriteRetarget(c *xun.Context, selector string)
- func WriteTrigger(c *xun.Context, key string, value any)
- type HxHeader
Constants ¶
const ( // HxBoosted indicates that the request is via an element using hx-boost HxBoosted = "HX-Boosted" // HxCurrentUrl the current URL of the browser HxCurrentUrl = "HX-Current-Url" // HxHistoryRestoreRequest “true” if the request is for history restoration after a miss in the local history cache HxHistoryRestoreRequest = "HX-History-Restore-Request" // HxPrompt the user response to an hx-prompt HxPrompt = "HX-Prompt" // HxRequest always “true” if it is htmx request HxRequest = "HX-Request" // HxTarget the id of the target element if it exists HxTarget = "HX-Target" // HxTriggerName the name of the triggered element if it exists HxTriggerName = "HX-Trigger-Name" // HxTrigger the id of the triggered element if it exists HxTrigger = "HX-Trigger" // HxLocation allows you to do a client-side redirect that does not do a full page reload HxLocation = "HX-Location" // HxPushUrl pushes a new url into the history stack HxPushUrl = "HX-Push-Url" // HxRedirect can be used to do a client-side redirect to a new location HxRedirect = "HX-Redirect" // HxRefresh if set to “true” the client-side will do a full refresh of the page HxRefresh = "HX-Refresh" // HxReplaceUrl replaces the current URL in the location bar HxReplaceUrl = "HX-Replace-Url" // HxReswap allows you to specify how the response will be swapped. See hx-swap for possible values HxReswap = "HX-Reswap" // HxRetarget a CSS selector that updates the target of the content update to a different element on the page HxRetarget = "HX-Retarget" // HxReselect a CSS selector that allows you to choose which part of the response is used to be swapped in. Overrides an existing hx-select on the triggering element HxReselect = "HX-Reselect" // HxTriggerAfterSettle allows you to trigger client-side events after the settle step HxTriggerAfterSettle = "HX-Trigger-After-Settle" // HxTriggerAfterSwap allows you to trigger client-side events after the swap step HxTriggerAfterSwap = "HX-Trigger-After-Swap" )
Variables ¶
var (
Json = xun.Json
)
Functions ¶
func CurrentURL ¶ added in v1.2.1
CurrentURL returns the current URL of the browser as reported by htmx via the "HX-Current-Url" header, or an empty string when the header is missing. This is the htmx-aware equivalent of the Referer header for HTMX requests.
func HandleFunc ¶ added in v1.1.3
func HandleFunc() xun.HandleFunc
HandleFunc serves the htmx.js library for the htmx extension.
func IsBoosted ¶ added in v1.2.1
IsBoosted reports whether the request was issued via an element that uses hx-boost.
func IsHistoryRestore ¶ added in v1.2.1
IsHistoryRestore reports whether the request was triggered by htmx's local history cache restoration after a miss.
func IsHxRequest ¶ added in v1.2.1
IsHxRequest reports whether the current request is an HTMX request. It returns true when the "HX-Request" header equals "true".
This is a convenience helper that mirrors (*interceptor).IsHxRequest without requiring callers to construct an interceptor instance. It lets handlers branch on HTMX behavior without registering xun.WithInterceptor, while still using the same header check that the interceptor performs.
func Prompt ¶ added in v1.2.1
Prompt returns the user response to an hx-prompt, or an empty string if no prompt was shown.
func Target ¶ added in v1.2.1
Target returns the id of the target element sent by htmx, or an empty string if it is not present.
func Trigger ¶ added in v1.2.1
Trigger returns the id of the triggered element sent by htmx, or an empty string if it is not present.
func TriggerName ¶ added in v1.2.1
TriggerName returns the name attribute of the triggered element sent by htmx, or an empty string if it is not present.
func WriteHeader ¶
WriteHeader writes the given value as a header with the given key. The value is marshaled to JSON before being written. If the value is a string, it is written as is.
func WriteLocation ¶ added in v1.2.1
WriteLocation instructs htmx to perform a client-side redirect that does not do a full page reload, while also replacing the current history entry. It writes the HX-Location header with a JSON-encoded location object, matching the htmx spec.
func WritePushUrl ¶ added in v1.2.1
WritePushUrl pushes the current URL of the browser into the history stack. To push a different URL, use WritePushUrlTo.
func WritePushUrlTo ¶ added in v1.2.1
WritePushUrlTo pushes the given URL into the history stack.
func WriteRedirect ¶ added in v1.2.1
WriteRedirect instructs htmx to perform a client-side redirect to url without a full page reload. It writes the HX-Redirect response header and sets the status code to 200 so the body is not rendered.
func WriteRefresh ¶ added in v1.2.1
WriteRefresh instructs htmx to do a full refresh of the page.
func WriteReplaceUrl ¶ added in v1.2.1
WriteReplaceUrl replaces the current URL in the location bar without adding a new entry to the history stack. To replace with a specific URL, use WriteReplaceUrlTo.
func WriteReplaceUrlTo ¶ added in v1.2.1
WriteReplaceUrlTo replaces the current URL in the location bar with the given URL.
func WriteReselect ¶ added in v1.2.1
WriteReselect sets the CSS selector that picks which part of the response is swapped in. It overrides any existing hx-select on the triggering element.
func WriteReswap ¶ added in v1.2.1
WriteReswap overrides the hx-swap strategy for the response. See https://htmx.org/reference/#response_headers for accepted values such as "innerHTML", "outerHTML", "beforebegin", "afterend", "none", or a swap timing extension like "innerHTML swap:200ms".
func WriteRetarget ¶ added in v1.2.1
WriteRetarget sets the CSS selector that updates the swap target of the response to a different element on the page. It writes the HX-Retarget response header.
func WriteTrigger ¶ added in v1.2.1
WriteTrigger sends an HTMX trigger response header so the client fires a custom event after the response is handled. It forwards to WriteHeader so a plain string is emitted as the bare event name and any other value (typically an HxHeader[T] map) is JSON-encoded and sent as the event detail.
Use it with HxTrigger for the default trigger step, or with HxTriggerAfterSettle / HxTriggerAfterSwap to fire on the later steps.
htmx.WriteTrigger(c, htmx.HxTrigger, "item-added")
htmx.WriteTrigger(c, htmx.HxTrigger, htmx.HxHeader[string]{"item-added": "abc"})