In order to support both Grails and Grace, reduce maintenance costs, and focus on developing new features, this repository is no longer being updated!
Please use grace-plugins/grace-htmx, it supports both Grails 3+ and Grace 2022!
Grails Plugin for using Grails with htmx.
Add dependency to the build.gradle
,
repositories {
mavenCentral()
}
dependencies {
// Grails 4
compile "org.rainboyan.plugins:grails-plugin-htmx:0.0.2"
// Grails 5+
implementation "org.rainboyan.plugins:grails-plugin-htmx:0.0.2"
}
Htmx plugin supports controller-specific withFormat()
method,
class BookController {
def list() {
def books = Book.list()
withFormat {
htmx {
render(template: "book", model: [bookList: books])
}
json {
render books as JSON
}
}
}
}
Also, this plugin supports extendsions for Grails Request and Response,
// You can get htmx request headers from Grails Request
request.htmx.boosted == request.getHeader('HX-Boosted')
request.htmx.target == request.getHeader('HX-Target')
// Check htmx request?
if (request.htmx as boolean) { // or use request.isHtmx()
template = 'book-detail'
}
// You can set htmx response headers in Grails
response.htmx.trigger = 'itemAdded'
git clone https://github.com/rainboyan/grails-htmx.git
cd grails-htmx
./gradlew publishToMavenLocal
- Grails 4.0, 4.1
- Grails 5.0, 5.1, 5.2, 5.3
- Grails 6.0
- Htmx 1.9
- Htmx 2.0
This plugin is available as open source under the terms of the APACHE LICENSE, VERSION 2.0