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
@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.
@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.
@spec reswap(term(), String.t()) :: Nex.Response.t()
Changes the swap method of the response.
Sets the HX-Reswap header.
@spec retarget(term(), String.t()) :: Nex.Response.t()
Changes the target element of the response.
Sets the HX-Retarget header.
@spec trigger(term(), String.t(), term()) :: Nex.Response.t()
Triggers a client-side event.
Sets the HX-Trigger header. Multiple triggers will be merged.
@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.
@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.