function Htmx::boost

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Htmx/Htmx.php \Drupal\Core\Htmx\Htmx::boost()

Creates a `data-hx-boost` attribute.

This attribute instructs HTMX to add progressive enhancement to links or forms. The attribute allows you to “boost” normal anchors and form tags to use AJAX instead. This has the nice fallback that, if the user does not have javascript enabled, the site will continue to work.

The simple syntax is `hx-boost="true"` or `hx-boost="false"`.

You can configure boost behavior using a config string that sets swap, target, and other options directly on the hx-boost attribute. Set the

Htmx::INHERITED;

modifier to pass that config down to all boosted descendants.

The documentation link below has more information on the syntax and precedence of the attributes between inherited and element attributes.

Parameters

bool|string $value: The value to be set for the attribute.

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-boost/

File

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

Class

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

Namespace

Drupal\Core\Htmx

Code

public function boost(bool|string $value = TRUE, int $modifiers = self::NO_MODIFIER) : static {
  if (is_bool($value)) {
    $value = $value ? 'true' : 'false';
  }
  $this->createStringAttribute('hx-boost', $value, $modifiers);
  return $this;
}

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