Version: v0.8.1 - Beta.  We welcome contributors & feedback.

Web.htmx

Web.htmx($mode, $dataMap) -> HtmlString

Description

Create HTML parameters for making an Ajax call using the HTMX JavaScript framework.

This will set up a POST request to the current page with the given data.

tem linkHtml {
    --- $htmx = Web.htmx('getThing', { id: 123 })
    <a {{ $htmx }} hx-target="#somediv"> Get Thing
}

Mode Function

The $mode defines which mode function will be called for the Ajax response.

You will usually want to return an HTML TypeString, which will replace the hx-target.

fun getThingMode {
    $id = Input.post('id')
    return thingHtml($id)
}

tem thingHtml($id) {
    <.thing> Thing {{ $id }}
}

To see how “hx-” parameters work, see HTMX parameters.

Including the HTMX Library

You will need to include the HTMX library on the client-side.

For example:

$page = Page.create({
    ...
    js: [url'https://unpkg.com/htmx.org@1.5.0']
})

See Also