hxfiber

package
v4.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 19, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// HxBoosted is set to "true" when the request comes from a boosted element via hx-boost.
	//
	// Contents: "true" or not set
	//
	// See https://four.htmx.org/reference/headers/HX-Boosted for more details.
	//
	// Use the IsBoosted() function to check this header in the request.
	HxBoosted = hx.HxBoosted
	// HxCurrentUrl contains the browser’s URL when the request was made.
	//
	// Contents: URL
	//
	// See https://four.htmx.org/reference/headers/HX-Current-URL for more details.
	//
	// Use the GetCurrentUrl() function to fetch this header from the request.
	HxCurrentUrl = hx.HxCurrentUrl
	// HxHistoryRestoreRequest is set to "true" when the user navigates back or forward in history.
	//
	// Contents: "true" or not set
	//
	// See https://four.htmx.org/reference/headers/HX-History-Restore-Request for more details.
	//
	// Use the IsHistoryRestoreRequest() function to check this header in the request.
	HxHistoryRestoreRequest = hx.HxHistoryRestoreRequest
	// HxRequest indicates the request was made by htmx.
	//
	// Contents: "true"
	//
	// See https://four.htmx.org/reference/headers/HX-Request for more details.
	//
	// Use the IsRequest() function to check this header in the request.
	HxRequest = hx.HxRequest
	// HxRequestType indicates if request targets a specific element or the whole page.
	//
	// Contents: "partial" or "full"
	//
	// See https://four.htmx.org/reference/headers/HX-Request-Type for more details.
	//
	// Use the GetRequestType() function to fetch this header from the request.
	HxRequestType = hx.HxRequestType
	// HxSource contains the element that triggered the request. Format is tag#id like button#submit.
	//
	// Contents: Element reference
	//
	// See https://four.htmx.org/reference/headers/HX-Source for more details.
	//
	// Use the GetSource() function to fetch this header from the request.
	HxSource = hx.HxSource
	// HxTarget identifies the element that will receive the response.
	//
	// Contents: Element reference
	//
	// See https://four.htmx.org/reference/headers/HX-Target for more details.
	//
	// Use the GetTarget() function to fetch this header from the request.
	HxTarget = hx.HxTarget
)
View Source
const (
	HxTrigger    = hx.HxTrigger    // HxTrigger triggers client-side events after the swap has completed.
	HxLocation   = hx.HxLocation   // HxLocation redirects without reloading the page.
	HxRedirect   = hx.HxRedirect   // HxRedirect redirects to a new URL with a full page reload.
	HxRefresh    = hx.HxRefresh    // HxRefresh when set to true, reloads the entire page.
	HxRetarget   = hx.HxRetarget   // HxRetarget overrides the element that'll receive the swapped content, replacing whatever hx-target was set on the triggering element.
	HxReswap     = hx.HxReswap     // HxReswap overrides the swap style used when inserting the response, replacing whatever hx-swap was set on the triggering element.
	HxReselect   = hx.HxReselect   // HxReselect allows selection of a specific part of the response to be swapped in, using a CSS selector. It overrides any existing hx-select on the triggering element.
	HxReplaceUrl = hx.HxReplaceUrl // HxReplaceUrl replaces the current browser history URL.
	HxPushUrl    = hx.HxPushUrl    // HxPushUrl pushes a new URL into the history stack.

	SwapInnerHtml   = hx.SwapInnerHtml   // Replaces content inside element.
	SwapOuterHtml   = hx.SwapOuterHtml   // Replaces entire element.
	SwapTextContent = hx.SwapTextContent // Replaces the text content of the element, without parsing the response as HTML.
	SwapBefore      = hx.SwapBefore      // Inserts content before element.
	SwapPrepend     = hx.SwapPrepend     // Inserts content as first child.
	SwapAppend      = hx.SwapAppend      // Inserts content as last child.
	SwapAfter       = hx.SwapAfter       // Inserts content after element.
	SwapInnerMorph  = hx.SwapInnerMorph  // Morphs content inside element, preserving state and focus.
	SwapOuterMorph  = hx.SwapOuterMorph  // Morphs entire element, preserving state and focus.
	SwapOuterSync   = hx.SwapOuterSync   // Morphs the target’s attributes, then replaces its children.
	SwapDelete      = hx.SwapDelete      // Removes element (ignores response content).
	SwapNone        = hx.SwapNone        // Doesn’t insert content.
	SwapUpsert      = hx.SwapUpsert      // Updates existing elements by ID and inserts new ones.
)

Variables

This section is empty.

Functions

func GetCurrentUrl

func GetCurrentUrl(ctx fiber.Ctx) string

GetCurrentUrl extracts the HxCurrentUrl header from an HTTP request.

Returns the current URL of the browser if the header exists.

func GetRequestType

func GetRequestType(ctx fiber.Ctx) string

GetRequestType extracts the HxRequestType header from an HTTP request.

Returns either "partial" or "full"

func GetSource

func GetSource(ctx fiber.Ctx) string

GetSource extracts the HxSource header from an HTTP request.

Returns the element reference of the source if the header exists.

func GetTarget

func GetTarget(ctx fiber.Ctx) string

GetTarget extracts the HxTarget header from an HTTP request.

Returns the element reference of the target if the header exists.

func Headers

func Headers(ctx fiber.Ctx, options ...HeaderOption) error

Headers modify the fiber.Ctx to add HTMX headers.

The following options are available:

  • Location(path): Enables client-side redirection without a full page reload.
  • PushUrl(string): Pushes a new URL into the history stack.
  • Redirect(string): Performs a client-side redirect with a full page reload.
  • Refresh(): Triggers a full refresh of the client-side page.
  • ReplaceUrl(string): Replaces the current URL in the location bar.
  • Reswap | {Swap constants}: Specifies an override for how the response will be swapped.
  • Retarget(string): A CSS selector to update the target of the content update to a different page element.
  • Reselect(string): A CSS selector to select a part of the response to be swapped in, overriding existing hx-select on the triggering element.
  • Trigger(...TriggerEvent): Triggers client-side events.

func IsBoosted

func IsBoosted(ctx fiber.Ctx) bool

IsBoosted checks the HxBoosted header

Returns true if the request is a boosted request

func IsHistoryRestoreRequest

func IsHistoryRestoreRequest(ctx fiber.Ctx) bool

IsHistoryRestoreRequest checks the HxHistoryRestoreRequest header

Returns true if the header is present, otherwise returns false.

func IsHtmx

func IsHtmx(ctx fiber.Ctx) bool

IsHtmx determines if an HTTP request is an HTMX request.

Does the same thing as IsRequest, only with a more user-friendly name.

func IsRequest

func IsRequest(ctx fiber.Ctx) bool

IsRequest determines if an HTTP request is an HTMX request by checking the HxRequest header

Returns true if the header is present, otherwise returns false.

func IsRequestTypeFull

func IsRequestTypeFull(ctx fiber.Ctx) bool

IsRequestTypeFull determines if the HxRequestType was "full"

Returns true if the HxRequestType was "full", otherwise returns false.

func IsRequestTypePartial

func IsRequestTypePartial(ctx fiber.Ctx) bool

IsRequestTypePartial determines if the HxRequestType was "partial"

Returns true if the HxRequestType was "partial", otherwise returns false.

Types

type HeaderOption

type HeaderOption = hx.HeaderOption

HeaderOption is the interface that can be used to set the headers and status code of the response.

type HeaderOptionFunc

type HeaderOptionFunc = hx.HeaderOptionFunc

HeaderOptionFunc is a function that can be used to set the headers and status code of the response.

func PushUrl

func PushUrl(url any) HeaderOptionFunc

PushUrl replaces the current browser history URL. It creates a new entry for back and forward navigation.

func Refresh

func Refresh() HeaderOptionFunc

Refresh sets the HxRefresh header.

func ReplaceUrl

func ReplaceUrl(url any) HeaderOptionFunc

ReplaceUrl replaces the current browser history URL. It does not create a new history entry.

func Trigger

func Trigger(events ...any) HeaderOptionFunc

Trigger allows you to trigger events on the client.

type HxHeaders

type HxHeaders = hx.HxHeaders

HxHeaders is a struct that contains the headers and status code to be returned to the client.

type LocationProperties

type LocationProperties = hx.LocationProperties // LocationProperties configures the HxLocation response header.

func Location

func Location(path string) *LocationProperties

Location sets the HxLocation header on a response.

type Redirect

type Redirect = hx.Redirect // Redirect sets the HxRedirect header.

type Reselect

type Reselect = hx.Reselect // Reselect sets the HxReselect header.

type Reswap

type Reswap = hx.Reswap // Reswap overrides the swap style used when inserting the response.

type ReswapModifiers

type ReswapModifiers = hx.ReswapModifiers // ReswapModifiers configures modifiers for a Reswap response header.

type Retarget

type Retarget = hx.Retarget // Retarget sets the HxRetarget header.

type TriggerEvent

type TriggerEvent = hx.TriggerEvent // TriggerEvent is a deferred serialization of an HTMX trigger event.

func Event

func Event(name string, data ...any) TriggerEvent

Event creates an event to pass into the Trigger() function.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL