function Htmx::swap
Creates a `data-hx-swap` attribute.
This attribute allows you to specify how the response will be swapped into the DOM relative to the target of an AJAX request.
Parameters
string $strategy: The swap strategy.
string $modifiers: Optional modifiers for changing the behavior of the swap.
bool $ignoreTitle: Instruct HTMX not to swap in the page title from the request.
Return value
static Returns this object to allow chaining methods.
See also
https://htmx.org/attributes/hx-swap/
File
-
core/
lib/ Drupal/ Core/ Htmx/ Htmx.php, line 736
Class
- Htmx
- Presents the HTMX controls for developers to use with render arrays.
Namespace
Drupal\Core\HtmxCode
public function swap(string $strategy, string $modifiers = '', bool $ignoreTitle = TRUE) : static {
if ($modifiers !== '') {
$strategy .= ' ' . $modifiers;
}
// HTMX defaults this behavior to FALSE, that is it replaces the page title.
// We believe our most common use case is to not change the title.
if ($ignoreTitle) {
$strategy .= ' ignoreTitle:true';
}
$this->createStringAttribute('hx-swap', $strategy);
return $this;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.