function Htmx::status

Creates a `data-hx-status` attribute.

This attribute allows different swap behavior to be configured per HTTP response status code, overriding the element's default hx-swap behavior for matching responses.

The code may be an exact status code (e.g. "422"), a single-digit wildcard (e.g. "50x"), or a range wildcard (e.g. "5xx").

The strategy string supports the following configuration keys:

  • swap: The swap strategy to use (see hx-swap).
  • target: The target element (see hx-target).
  • select: The selector to extract from the response (see hx-select).
  • push: (boolean) Whether to push the request URL into history.
  • replace: (boolean) Whether to replace the current URL in history.
  • transition: (boolean) Whether to use the View Transition API.

Parameters

string $code: The HTTP status code, or code wildcard, this configuration applies to.

string $strategy: The status-code-specific configuration, expressed as space-separated key:value pairs (e.g. "swap:innerHTML target:#errors").

int $modifiers: The modifiers to apply to the attribute. Defaults to no modifiers.

Return value

static Returns this object to allow chaining methods.

See also

https://four.htmx.org/reference/attributes/hx-status

File

core/lib/Drupal/Core/Htmx/Htmx.php, line 901

Class

Htmx
Presents the HTMX controls for developers to use with render arrays.

Namespace

Drupal\Core\Htmx

Code

public function status(string $code, string $strategy, int $modifiers = self::NO_MODIFIER) : static {
  $this->createStringAttribute("hx-status:{$code}", $strategy, $modifiers);
  return $this;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.