Skip to content

Request, Response & Partials

Beyond Ui and Component, $this->wire()->htmx gives every ProcessWire template and URL hook full access to HTMX 4’s HTTP protocol through $htmx->request, $htmx->response, and $htmx->fragment.

Inspecting Incoming Requests ($htmx->request)

Section titled “Inspecting Incoming Requests ($htmx->request)”
Method Return / Purpose
isHtmx() true when the request carries HX-Request: true.
isBoosted() true when triggered by hx-boost="true".
isHistoryRestore() true when HTMX is restoring a history cache miss.
isFullPage() true when the request is not an HTMX partial request.
isPartial() true when HTMX expects a partial HTML fragment rather than a full document.
isQuery() true when the HTTP verb is QUERY (or GET query mode).
isQueryActionRequest() true when dispatching a read-only query* component action.
validateCsrf() Validates the ProcessWire $session->CSRF token on incoming HTMX mutations.
fake(array $headers = []) Simulates HTMX request headers in Pest/PHPUnit tests without live HTTP requests.

Emitting HTMX 4 Response Headers ($htmx->response)

Section titled “Emitting HTMX 4 Response Headers ($htmx->response)”
Method Emitted Header / Effect
redirect(string $url) HX-Redirect: performs a full client-side navigation.
refresh() HX-Refresh: true: triggers a full browser reload.
location(string|array $target) HX-Location: client-side navigation without full reload (supports target/swap JSON).
pushUrl(string|false $url) HX-Push-Url: pushes a new URL onto browser history (or false to disable).
replaceUrl(string|false $url) HX-Replace-Url: replaces the current URL in browser history.
retarget(string $selector) HX-Retarget: overrides the target CSS selector for the swap.
reselect(string $selector) HX-Reselect: picks a sub-element from the response HTML to swap.
reswap(string $style) HX-Reswap: overrides the swap strategy (validated via isValidSwapStyle()).
noSwap() Sets HX-Reswap: none so the DOM is left untouched while headers/triggers still fire.
trigger(string $event, mixed $detail = null) HX-Trigger: dispatches a client-side event immediately upon response.
triggerAfterSwap(string $event, mixed $detail = null) HX-Trigger-After-Swap: dispatches an event after DOM swap completes.
triggerAfterSettle(string $event, mixed $detail = null) HX-Trigger-After-Settle: dispatches an event after CSS transitions settle.
stopPolling() Sends HTTP status 286 to stop hx-trigger="every Ns" polling cleanly.
vary() Appends HX-Request (and related headers) to the Vary header for safe proxy caching.

Multi-Target <hx-partial> Updates ($htmx->fragment)

Section titled “Multi-Target <hx-partial> Updates ($htmx->fragment)”

Update multiple independent regions of the page in a single server round-trip using HTMX 4’s native <hx-partial> elements:

$htmx = $this->wire()->htmx;
$htmx->fragment
->addPartial('#fleet-count', '<span>14 yachts available</span>', 'innerHTML')
->addPartial('#active-filters', '<span class="pill">Gocek</span>', 'innerHTML');
echo $htmx->fragment->renderPartials();

You can also render standalone template fragment files safely with $htmx->fragment->renderFile('partials/yacht-summary.php', ['yacht' => $yacht]).

Next steps