Version: v0.7.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.

tm 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.

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

tm 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