Return only main content for endpoints designed to service htmx requests

Created on 3 September 2025, about 1 month ago

Problem/Motivation

When we intentionally build responses to service HTMX requests it is the main content that we want to send. We don't want or need all the surrounding blocks that Drupal generates. In such cases we need to be able to produce a simple response with the main content.

Proposed resolution

Use the new renderer created in πŸ“Œ Return htmx responses as SimplePageVariant Active to render these responses.

Two possibilities occur to us to signal the use of this renderer when building a service to return fragments or html intentionally built for htmx requests.

  1. Add logic to \Drupal\Core\EventSubscriber\MainContentViewSubscriber which selects this renderer if the route is designated as an _htmx_route. MainContentViewSubscriber already has the current RouteMatch available which makes this a straightforward change.
  2. Create an HtmxResponse object and find the right point in the response process to select the renderer.

Remaining tasks

  1. Decide on the best approach.
  2. Implement.

User interface changes

None.

Introduced terminology

None.

API changes

  1. Add a new wrapper format for the responses that can be used by adding _wrapper_format=drupal_htmx to the query string.
  2. Define a route option, _htmx_route.
  3. Create an HtmxRenderer which renders the main content and required CSS/JS assets in the simplest HTML document.

Data model changes

None at this time.

Release notes snippet

πŸ“Œ Task
Status

Needs work

Version

11.0 πŸ”₯

Component

request processing system

Created by

πŸ‡ΊπŸ‡ΈUnited States fathershawn New York

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024