Boosted links htmx
hx-boost turns plain links and forms into ajax page loads; the framework treats them as page views, not as fragment requests.
Options
| Option | Meaning |
|---|---|
hx-boost="true" | On a container: its links and forms load the page by ajax, swap the body and push the URL. |
req['boosted'] | HX-Boosted: true for such a request (_class('htmx')->boosted). |
Example
This request: boosted = false (follow a link below, then look again).
Code
$hx = _class('htmx');
asset('htmx');
return '<p>This request: <code>boosted = ' . ($hx->req['boosted'] ? 'true' : 'false') . '</code> (follow a link below, then look again).</p>'
. '<nav hx-boost="true" class="docs-ref-boost">'
. html()->a(url('/@object/htmx/boost'), 'This page, boosted', 'fa fa-bolt', '', '', '_self') . ' '
. html()->a(url('/@object/htmx/request'), 'The request entry, boosted', 'fa fa-bolt', '', '', '_self')
. '</nav>';Notes
- A boosted request wants the whole page:
admin_post::is_htmx()andyf_redirect::$HTMX_REDIRECTignore it, so a boosted link to an admin action shows the confirm page and a redirect stays a redirect. - A module that answers fragments should check
_wants_fragment()and the target, not onlyis_hx: a boosted navigation is htmx too. - The admin and the docs pages do not boost by default; a site boosts its own navigation where the layout allows it.
See also: htmx/request, htmx/admin_confirm