Overview

Last updated on
16 September 2025

Callbacks, Ajax responses, and HTML

HTMX uses HTML as its data structure, so what we are doing is building a rendered response.

Callbacks

Much of the logic in a callback that returns a render array can probably be repurposed as part of conditionally building the render array.  However, in a form the form is built the first time before there is input and the callback usually is reacting to some kind of input.  We have found in our initial trials that checking for input and passing values to the callback is necessary.

Triggers

The ajax callback system takes care of the triggering element, as the callback is attached to a specific element's render array.  With HTMX we need to check for triggers and alter the response accordingly.  We are working on convenience methods in #3544486: Add methods to get info about which elements are involved in an HTMX Request.  Until those exist, header values need to be directly checked.

$trigger = $this->getRequest()->headers->get('HX-Trigger-Name');

Help improve this page

Page status: No known problems

You can: