On this page
Overview
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
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion
Still on Drupal 7? Security support for Drupal 7 ended on 5 January 2025. Please visit our Drupal 7 End of Life resources page to review all of your options.