Change record status: 
Project: 
Introduced in branch: 
11.3.x
Introduced in version: 
11.3.0
Description: 

Drupal uses wrapper format query parameters to adjust the format of responses on a given path. Drupal 11.3 adds a wrapper format for use with HTMX. This format returns the main content and needed JS/CSS assets in a very simple document.

The template used for the markup is very streamlined:

<html>
  <head>
    <title>{{ title }}</title>
    <css-placeholder token="{{ placeholder_token }}">
    <js-placeholder token="{{ placeholder_token }}">
    <js-bottom-placeholder token="{{ placeholder_token }}">
  </head>
  <body>{{ content }}</body>
</html>

To use this format, add the query parameter to your url:

$options = [
      'query' => [
        MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_htmx',
      ],
    ];
$url = Url::fromRoute('config.export_single', [], $options);
(new Htmx())
  ->post($url)
  ->select('*:has(>select[name="config_name"])')
  ->target('*:has(>select[name="config_name"])')
  ->swap('outerHTML')
  ->applyTo($form['config_type']);
Impacts: 
Module developers
Site templates, recipes and distribution developers