Skip to content

HTMX: poll region

Available since: 3.1.3

Build a region that periodically polls a URL via HTMX and swaps in the returned markup. The polled fragment can be served by an ECA endpoint (see the ECA Endpoint module).

Only main content

The only main content option is enabled by default. When enabled, the polled URL is requested with the Drupal "only main content" hint, so the response is the minimal HTMX render (the main content wrapped in a bare HTML document) rather than a full themed page. Disable it only if the polled URL already returns a fragment by other means.

A natural source for the polled fragment is an ECA endpoint. See Building HTMX-powered interfaces with ECA.

Fields

Poll URL

The URL that HTMX requests on every poll. The response markup replaces the polled region. An ECA endpoint can serve this fragment.
This field supports tokens.

Poll interval (seconds)

The number of seconds between two polls.
This field supports tokens.

Swap strategy

The HTMX swap strategy, for example innerHTML, outerHTML or beforeend.
This field supports tokens.

Swap target

Optional CSS selector identifying the element that receives the swapped content. When left empty, the polling region itself is the target.
This field supports tokens.

Initial content

The markup shown inside the region before the first poll completes.
This field supports tokens.

Wrapper tag

The HTML tag of the polling region, for example div or span.
When using the "Defined by token" option, make sure there is a token with this name: eca_htmx_poll_wrapper_tag

Request only the main content

When enabled, the polled URL is requested with the Drupal "only main content" hint, so the response is the minimal HTMX render rather than a full HTML page.

Machine 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.

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.

Element weight

Optionally specify an element weight. The lower the weight, the element appears before other elements having a higher weight.

Build mode


When using the "Defined by token" option, make sure there is a token with this name: eca_htmx_poll_mode