HTMX Integration

HexPHP natively includes HTMX to swap components on the fly without heavy JavaScript frameworks or full page refreshes.

Checking for HTMX Requests

Because HTMX requests only expect a small chunk of HTML (a component) in return rather than a full page with the Navbar and Footer layout, you handle this within the Controller.

<?php
public function loadWidget(): void
{
    // Normally you'd wrap this in the Framework.php layout.
    // Instead, since HTMX is requesting it, just require the component!
    
    require BASE_PATH . '/app/Components/my_widget.php';
}

Live Example

Click the button below. It will make a GET request via HTMX to the /docs/htmx-demo route. That route simply requires an HTML component which HTMX swaps safely into the DOM.

This container will be completely replaced by the component.