htmx

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: May 26, 2026 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FS

func FS(filesystem embed.FS, directory string) fs.FS

FS wraps an embedded filesystem with a subdirectory for template loading.

func SetNoSwap

func SetNoSwap(w http.ResponseWriter) error

SetNoSwap disables the hx-swap attribute; causing the existing content to remain in place after HTMX transition.

Useful for setting error messages on forms, allowing users to try again.

func SetRedirect

func SetRedirect(w http.ResponseWriter, path string) error

SetRedirect forces a client-side redirect using HTMX.

Must use this instead of http.SetRedirect when doing a redirect from a request triggered by an HTMX element.

func Write

func Write(w http.ResponseWriter, components ...Interface) error

Write renders and writes an HTMX response using a variadic list of components, separated by newlines. It panics if any component fails to write.

Types

type Component

type Component struct {
	HTML   string
	Fields any
	Funcs  template.FuncMap
}

Component is a raw HTML string rendered using html/template. Fields provides data to the template via the dot (.) context. Funcs allows providing custom template functions.

func (*Component) Write

func (c *Component) Write(w io.Writer) error

Write renders the HTML template with Fields and writes the result to w.

type Interface

type Interface interface {
	Write(io.Writer) error
}

An Interface is used to render an HTMX response. Included by default are implementations for rendering plain text, raw HTML, and file based Go html/templates.

type Template

type Template struct {
	FS       fs.FS
	Filename string
	Fields   any
	Funcs    template.FuncMap
}

Template represents an html/template file loaded from an embedded filesystem. Fields provides data to the template via the dot (.) context. Funcs allows providing custom template functions.

func (*Template) Write

func (t *Template) Write(w io.Writer) error

Write renders the template file with Fields and writes the result to w.

type Text

type Text[T ~string] struct {
	Content T
}

Text is plain text content for HTMX responses.

func (*Text[T]) Write

func (t *Text[T]) Write(w io.Writer) error

Write writes the plain text content to w.

Jump to

Keyboard shortcuts

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