From drupal-htmx
Implements HTMX in Drupal 11.3+ for dynamic forms, dependent dropdowns, infinite scroll, real-time validation, and multi-step wizards. Migrates AJAX to HTMX.
How this skill is triggered — by the user, by Claude, or both
Slash command
/drupal-htmx:htmx-developmentThis skill is limited to the following tools:
The summary Claude sees in its skill listing — used to decide when to auto-load this skill
Drupal 11.3+ HTMX implementation and AJAX migration guidance.
Drupal 11.3+ HTMX implementation and AJAX migration guidance.
references/ajax-reference.md)| Choose HTMX | Choose AJAX |
|---|---|
| New features | Existing AJAX code |
| Declarative HTML preferred | Complex command sequences |
| Returns HTML fragments | Dialog commands needed |
| Progressive enhancement needed | Contrib expects AJAX |
Hybrid OK: Both systems coexist. Migrate incrementally.
Attach HTMX behavior to a render element with the Htmx class:
use Drupal\Core\Htmx\Htmx;
use Drupal\Core\Url;
(new Htmx())
->get(Url::fromRoute('my.content'))
->onlyMainContent()
->target('#result')
->swap('innerHTML')
->applyTo($build['button']);
The controller returns a render array (['#markup' => '...']); add
_htmx_route: TRUE to the route's options for an always-minimal response.
Full setup — basic usage, route configuration, dual-purpose routes — is in
references/htmx-implementation.md.
| Use Case | Pattern | Key Methods |
|---|---|---|
| Dependent dropdown | Form partial update | select(), target(), swap('outerHTML') |
| Load more | Append content | swap('beforeend'), trigger('click') |
| Infinite scroll | Auto-load | swap('beforeend'), trigger('revealed') |
| Real-time validation | Blur check | trigger('focusout'), field update |
| Multi-step wizard | URL-based steps | pushUrl(), route parameters |
| Multiple updates | OOB swap | swapOob('outerHTML:#selector') |
Each pattern has full before/after code in references/migration-patterns.md
(7 patterns) and references/htmx-implementation.md (dependent dropdowns, OOB
updates, URL history).
get() / post() / put() / patch() / delete() (take a Url)target(), select(), swap(), swapOob(), trigger(), vals(), onlyMainContent()pushUrlHeader(), redirectHeader(), triggerHeader(), reswapHeader(), retargetHeader()applyTo($element) or applyTo($element, '#wrapper_attributes')Complete method and header tables: references/quick-reference.md.
Forms include HtmxRequestInfoTrait automatically; controllers add it manually:
if ($this->isHtmxRequest()) {
$trigger = $this->getHtmxTriggerName();
}
Controller setup and the full 8-method detection API are in
references/htmx-implementation.md.
#ajax propertiesHtmx classbuildForm()getHtmxTriggerName() for conditional logicAjaxResponse with render arraysThe FAPI quick map (#ajax → Htmx equivalents), command-level mappings, and
7 detailed before/after patterns are in references/migration-patterns.md and
references/quick-reference.md.
This skill's work forms a natural gradient — scaffold, validate, cross-reference.
Scale it to the active effort level, ${CLAUDE_EFFORT}:
${CLAUDE_EFFORT} | Depth |
|---|---|
low | Emit the HTMX scaffolding (Quick Start + the relevant Core Pattern) and stop. |
medium and above | Also run the Validation Checklist below inline against what was produced. |
high / xhigh / max | Additionally delegate to /dev-guides-navigator for drupal/forms and drupal/js-development to cross-reference FAPI and behavior patterns. |
When ${CLAUDE_EFFORT} is unset (model without effort support), default to the
medium depth.
When reviewing HTMX implementations:
Htmx class used (not raw attributes)onlyMainContent() for minimal responsearia-live for dynamic regions| Problem | Solution |
|---|---|
| Content not swapping | Check target() selector exists |
| Wrong content extracted | Check select() selector |
| JS not running | Verify htmx:drupal:load fires |
| Form not submitting | Check post() and URL |
| Multiple swaps fail | Add swapOob('true') to elements |
| History broken | Use pushUrlHeader() |
Extended troubleshooting: references/htmx-implementation.md.
references/quick-reference.md — command equivalents, method/header tablesreferences/htmx-implementation.md — full Htmx class API, detection, routes, JSreferences/migration-patterns.md — 7 patterns with before/after code, FAPI quick mapreferences/ajax-reference.md — AJAX commands for understanding existing codeFor deeper Drupal context beyond bundled references, invoke
/dev-guides-navigator with keywords like "Drupal forms", "routing", "JS
development", or "render API". The navigator handles caching and disambiguation
— never fetch dev-guides URLs directly. Relevant topics: drupal/forms,
drupal/routing, drupal/js-development, drupal/render-api.
core/lib/Drupal/Core/Htmx/Htmx.php — Main APIcore/lib/Drupal/Core/Htmx/HtmxRequestInfoTrait.php — Request detectioncore/lib/Drupal/Core/Render/MainContent/HtmxRenderer.php — Response renderercore/modules/config/src/Form/ConfigSingleExportForm.php — Production examplecore/modules/system/tests/modules/test_htmx/ — Test examplesnpx claudepluginhub camoa/claude-skills --plugin drupal-htmxBuild dynamic web interfaces with htmx using hypermedia-driven patterns for partial page updates, lazy loading, infinite scroll, and server-sent events without JavaScript.
Provides htmx 4.0.0 migration guidance, configuration, and reference for events, history, requests, swaps, and extensions. Use when implementing, debugging, or upgrading htmx applications.