repositorypackage
0.1.0
Repository: https://github.com/nodxdev/nodxgo-htmx.git
Documentation: pkg.go.dev
# README
nodxgo-htmx
Overview
nodxgo-htmx provides Go-based integration for HTMX within the NodX Go template engine. This package enables the generation of dynamic HTML attributes and server-side helpers for handling HTMX requests efficiently.
Installation
To install the package, run:
# Go 1.22 or later is required
go get github.com/nodxdev/nodxgo-htmx
Usage
You can see all the included functions in the Go reference or with your editor's auto-completion.
Example: Using HTMX Attributes
hx-get
Attribute
node := nodx.Div(
htmx.HxGet("/api/data"),
)
fmt.Println(node)
Output:
<div hx-get="/api/data"></div>
hx-trigger
Attribute
node := nodx.Button(
htmx.HxTrigger("click"),
nodx.Text("Click Me"),
)
fmt.Println(node)
Output:
<button hx-trigger="click">Click Me</button>
Example: Using Server Helpers
Detecting an HTMX Request
func handler(w http.ResponseWriter, r *http.Request) {
if htmx.ServerGetIsHtmxRequest(r.Header) {
fmt.Println("HTMX request detected")
}
}
Setting a Redirect via Response Header
func handler(w http.ResponseWriter, r *http.Request) {
htmx.ServerSetRedirect(w.Header(), "/new-url")
w.WriteHeader(http.StatusOK)
}
License
This project is licensed under the MIT License.
Contributing
Contributions are welcome! Feel free to open issues or submit pull requests to improve the project.
For more details, check out the HTMX documentation and NodX Go.