Nex.HTMX (nex_core v0.4.3)

Copy Markdown

Pipeline-friendly functions for generating HTMX responses.

These functions allow you to attach HTMX-specific headers (like HX-Trigger, HX-Push-Url) to your HEEx templates seamlessly.

Example

def create_todo(req) do
  ~H"""
  <div id="todo-1">New Todo</div>
  """
  |> push_url("/todos/1")
  |> trigger("todo-created", %{id: 1})
end

Summary

Functions

Pushes a new URL into the browser's history stack. Sets the HX-Push-Url header.

Replaces the current URL in the browser's history stack. Sets the HX-Replace-Url header.

Changes the swap method of the response. Sets the HX-Reswap header.

Changes the target element of the response. Sets the HX-Retarget header.

Triggers a client-side event. Sets the HX-Trigger header. Multiple triggers will be merged.

Triggers a client-side event after the settle step. Sets the HX-Trigger-After-Settle header.

Triggers a client-side event after the swap step. Sets the HX-Trigger-After-Swap header.

Functions

push_url(html_or_resp, url)

@spec push_url(term(), String.t()) :: Nex.Response.t()

Pushes a new URL into the browser's history stack. Sets the HX-Push-Url header.

replace_url(html_or_resp, url)

@spec replace_url(term(), String.t()) :: Nex.Response.t()

Replaces the current URL in the browser's history stack. Sets the HX-Replace-Url header.

reswap(html_or_resp, swap_style)

@spec reswap(term(), String.t()) :: Nex.Response.t()

Changes the swap method of the response. Sets the HX-Reswap header.

retarget(html_or_resp, selector)

@spec retarget(term(), String.t()) :: Nex.Response.t()

Changes the target element of the response. Sets the HX-Retarget header.

trigger(html_or_resp, event_name, detail \\ nil)

@spec trigger(term(), String.t(), term()) :: Nex.Response.t()

Triggers a client-side event. Sets the HX-Trigger header. Multiple triggers will be merged.

trigger_after_settle(html_or_resp, event_name, detail \\ nil)

@spec trigger_after_settle(term(), String.t(), term()) :: Nex.Response.t()

Triggers a client-side event after the settle step. Sets the HX-Trigger-After-Settle header.

trigger_after_swap(html_or_resp, event_name, detail \\ nil)

@spec trigger_after_swap(term(), String.t(), term()) :: Nex.Response.t()

Triggers a client-side event after the swap step. Sets the HX-Trigger-After-Swap header.