htmx reference

13 entries for 19 methods. Each entry runs its example on this page and shows its code.

Overview

htmx in yfHow the framework uses htmx: the asset, the request and response helpers of _class('htmx'), and the features built on them.

Request

_is_hx(), _get_req()Tell an htmx request from a plain one and read its HX-* headers: is_hx, req[target], req[trigger], req[boosted]...

Response helpers

Headers: _cache(), _cache_none(), _robot_none()Cache-Control and X-Robots-Tag of an htmx answer (yf_api): no-store for live data, none for fragments search engines must not index.
Refusals: _firewall(), _reject(), _forbidden(), _error()Keep an endpoint for htmx only (_firewall()), or end a request with 503, 403 or 500 and no page.
Partial responses: _result(), _wants_fragment(), _vary()Answer an htmx request with a fragment of the page and end the request; other requests (and a history restore) get the whole page.
Redirects: _redirect(), _location(), _refresh()Send htmx to another page (HX-Redirect), load a page into the current one without a reload (HX-Location), or reload (HX-Refresh).
_reswap(), _reselect()Let the server decide how (HX-Reswap) and which part (HX-Reselect) of its answer htmx swaps, over hx-swap / hx-select of the request.
_toast()Add a Bootstrap 5 toast to an htmx response (HX-Trigger event yf-toast); the response goes on.

Framework features

Admin confirm over htmxAn htmx GET to a state-changing admin action gets a confirm form in its target; Confirm posts the same URL with the token.
Boosted linkshx-boost turns plain links and forms into ajax page loads; the framework treats them as page views, not as fragment requests.
HX-Redirect and HX-Refresh of the frameworkHow the framework answers htmx where a page would redirect: HX-Redirect after an admin action, 401 + HX-Refresh for a logged-out admin.
Refresh controlA quick-settings button for live parts of a page: 5, 10, 30 s or Off, kept per account and page in a cookie; here it drives an htmx poll.
table2 paging, sort and live filtertable() with the htmx option: sort headers, a live filter and a pager or a "Load more" row, answered as fragments of the same URL.

Demos