lib

package
v0.0.0-...-680f995 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Coalesce

func Coalesce(v1, v2 string) string

Coalesce will check if the first value is an empty string and return v2 if it is empty, otherwise it will return v1.

func HxRender

func HxRender(c echo.Context, status int, page, cmp templ.Component) error

HxRender conditionally renders a component based on whether the request is an HTMX request.

If the request is an HTMX request, it renders the `cmp` component. Otherwise, it renders the `page` component.

func IIF

func IIF[T any](condition bool, v1, v2 T) T

IIF will return v1 if the condition is true, otherwise it will return v2.

func IsHTMX

func IsHTMX(c echo.Context) bool

IsHTMX checks if the request is an HTMX request.

It returns true if the request contains the "HX-Request" header, otherwise, it returns false.

func Redirect

func Redirect(c echo.Context, status int, route string) error

Redirect performs an HTTP redirect, with special handling for HTMX requests.

For HTMX requests, the "HX-Redirect" header is set with the route, and a 200 OK status is used. HTMX does not handle 3xx redirects, it only sees the final 2xx, 4xx, or 5xx response. For non-HTMX requests, a standard HTTP redirect is performed with the provided status.

See github.com/bigskysoftware/htmx/issues/2052#issuecomment-1979805051 for more details.

func Render

func Render(c echo.Context, status int, cmps ...templ.Component) error

Render renders zero to many templ.Component objects into an HTML response with the given status code.

It sequentially renders each component to an internal buffer and sends the result as an HTML response. If any component fails to render, the function returns the error immediately.

Types

This section is empty.

Jump to

Keyboard shortcuts

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