HTMX: render element¶
Plugin ID: eca_htmx_element
Available since: 3.1.3
Build an HTMX-enabled element with a configurable request method, trigger, swap, target and other common HTMX attributes.
Building HTMX interactions
This action builds a single element carrying the HTMX attributes you
configure (request method and URL, trigger, swap strategy, target, and
more). It attaches the core/drupal.htmx library automatically. Use it for
click-to-load fragments, infinite scroll, and similar interactions. For a
region that refreshes on a timer, use the
HTMX: poll region action
instead. See
Building HTMX-powered interfaces with ECA.
Fields¶
Request method— config key:method-
The HTTP method HTMX uses for the request.
When using the "Defined by token" option, make sure there is a token with this name: eca_htmx_element_methodType:
select· Required: no · Default:getAllowed values:
get,post,put,patch,delete,_eca_token,'' Request URL— config key:url-
The URL HTMX requests. Leave empty to request the current URL. Internal paths start with a slash, for example /node/1.
This field supports tokens.Type:
textfield· Required: no · Default: empty string Trigger— config key:trigger-
The HTMX trigger definition, for example click, change or every 5s.
This field supports tokens.Type:
textfield· Required: no · Default: empty string Swap strategy— config key:swap-
The HTMX swap strategy, for example innerHTML, outerHTML or beforeend.
This field supports tokens.Type:
textfield· Required: no · Default: empty string Target— config key:target-
Optional CSS selector identifying the element that receives the swapped content.
This field supports tokens.Type:
textfield· Required: no · Default: empty stringThe selector has to match an element that already exists on the page. This action gives the element it builds neither an
idnor a class, so one HTMX element cannot address another one by selector. Select— config key:select-
Optional CSS selector for the content to select from the response.
This field supports tokens.Type:
textfield· Required: no · Default: empty string Push URL— config key:push_url-
Optional URL to push to the browser history, or true/false to enable or disable pushing the fetched URL.
This field supports tokens.Type:
textfield· Required: no · Default: empty string Confirm message— config key:confirm-
Optional message to show in a confirmation dialog before the request is issued.
This field supports tokens.Type:
textfield· Required: no · Default: empty string Indicator— config key:indicator-
Optional CSS selector of the element that receives the htmx-request class during the request.
This field supports tokens.Type:
textfield· Required: no · Default: empty stringThe selector has to match an element that already exists on the page. This action gives the element it builds neither an
idnor a class, so one HTMX element cannot address another one by selector. Values— config key:vals-
Optional values to add to the request parameters, in YAML format, for example key: "[token]".
This field supports tokens.Type:
textarea· Required: no · Default: empty string Boost— config key:boost-
When enabled, anchors and forms inside the element are progressively enhanced to use AJAX.
Type:
checkbox· Required: no · Default:false Request only the main content— config key:htmx_only-
When enabled, the request is sent with the Drupal "only main content" hint, so the response is the minimal HTMX render rather than a full HTML page.
Type:
checkbox· Required: no · Default:false Initial content— config key:content-
The markup shown inside the element before any swap occurs.
This field supports tokens.Type:
textarea· Required: no · Default: empty string Wrapper tag— config key:wrapper_tag-
The HTML tag of the element, for example div, button or span.
When using the "Defined by token" option, make sure there is a token with this name: eca_htmx_element_wrapper_tagType:
select· Required: yes · Default:divAllowed values:
div,span,section,article,aside,nav,p,button,a,ul,ol,li,details,_eca_tokenbuttonsubmits the form it sits inThe element is built as a plain HTML tag and receives no
typeattribute, and HTML treats a<button>withouttypeastype="submit". Inside a form, for example under a Build form event, clicking it submits the form instead of issuing the HTMX request. Useaorspaninstead. Machine name— config key:name-
Optionally define a machine name of this render element. It will be made available under that name in the render array of the current event in scope. Nested elements can be set with using "][" brackets, for example details][title.
This field supports tokens.Type:
textfield· Required: no · Default: empty stringThe machine name is a key in the render array of the event in scope. ECA's form events expose the form array itself as their render array, so under a Build form or Process form event this name is a form element key, and
][nesting addresses nested form elements. See rendering HTMX elements into a form for what that makes possible.
Leaving the name empty is the usual choice for a standalone element. It is
unsafe only together with the Build mode value Set and clear any previous
value, which then replaces the whole render array instead of adding to it. See
the note on the Build mode field.
Token name— config key:token_name-
Optionally define a token name of this render element. It will be made available under that token name for later usage. Please provide the token name only, without brackets.
Type:
textfield· Required: no · Default: empty string Element weight— config key:weight-
Optionally specify an element weight. The lower the weight, the element appears before other elements having a higher weight.
This field supports tokens.Type:
textfield· Required: no · Default: empty string Build mode— config key:mode-
When using the "Defined by token" option, make sure there is a token with this name: eca_htmx_element_modeType:
select· Required: yes · Default:appendAllowed values:
set:clear,set:clear:defined,merge,prepend,append,nothing,_eca_tokenAn empty machine name clears the whole render array
With this field set to
Set and clear any previous valueand no Machine name, the action adds nothing: it replaces the entire render array of the event in scope with the element it just built. Under a Build form event, whose render array is the form itself, that discards the whole form.Use
Set value when machine name is defined abovewhenever the name comes from a token that might resolve to nothing. That mode leaves the target untouched while the name is empty.