function HtmxFragmentController::buildPartial
Builds the partial response.
Attributes
#[Route(path: '/test-htmx/htmx-fragment', name: 'htmx_fragment', defaults: [
'target' => '[data-drupal-wrapper-selector="edit-partial-replace"]',
'swap' => 'outerHTML',
])]
#[Route(path: '/test-htmx/htmx-fragment-delete', name: 'htmx_fragment_delete', defaults: [
'target' => '[data-drupal-wrapper-selector="edit-partial-replace"]',
'swap' => 'delete',
])]
File
-
core/
modules/ system/ tests/ modules/ test_htmx/ src/ Controller/ HtmxFragmentController.php, line 23
Class
- HtmxFragmentController
- Returns responses for HTMX Test Fixtures routes.
Namespace
Drupal\test_htmx\ControllerCode
public function buildPartial(string $target, string $swap) : array {
return [
'#type' => 'inline_template',
'#template' => <<<HTMX_PARTIAL
<hx-partial hx-target="{{ target }}" hx-swap="{{ swap }}">
{{item}}
</hx-partial>
HTMX_PARTIAL,
'#context' => [
'target' => $target,
'swap' => $swap,
'item' => $swap === 'delete' ? '' : [
'#type' => 'html_tag',
'#tag' => 'p',
'#value' => 'Inserted by htmx!',
],
],
];
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.