repositorypackage
0.1.0
Repository: https://github.com/nodxdev/nodxgo-alpine.git
Documentation: pkg.go.dev
# README
nodxgo-alpine
nodxgo-alpine provides a Go-based integration for Alpine.js within the NodX Go template engine. It simplifies the generation of dynamic HTML elements and attributes using Alpine.js directives.
Installation
To install the package, run:
# Go 1.22 or later is required
go get github.com/nodxdev/nodxgo-alpine
Usage
Example: Using Alpine.js Directives
x-data
Directive
node := nodx.Div(
alpine.XData("{ count: 0 }"),
)
fmt.Println(node)
Output:
<div x-data="{ count: 0 }"></div>
x-bind
Directive
node := nodx.Button(
alpine.XBind("disabled", "isDisabled"),
nodx.Text("Click Me"),
)
fmt.Println(node)
Output:
<button x-bind:disabled="isDisabled">Click Me</button>
Example: Rendering a Template
package main
import (
"fmt"
nodx "github.com/nodxdev/nodxgo"
alpine "github.com/nodxdev/nodxgo-alpine"
)
func main() {
node := alpine.Template(
nodx.Div(nodx.Text("Hello, World!")),
)
fmt.Println(node)
}
Output:
<template><div>Hello, World!</div></template>
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 Alpine.js documentation and NodX Go.