Phtmx.Request (Phtmx v0.2.0)

Copy Markdown View Source

Parsed HTMX request metadata, derived from the HX-* request headers that the HTMX client sends.

Phtmx.Plug builds one of these for every request and assigns it as conn.assigns.htmx, so controllers and templates can branch on it:

<div :if={@htmx.request?}>...only rendered for HTMX requests...</div>

def index(conn, _params) do
  if conn.assigns.htmx.boosted?, do: ..., else: ...
end

Summary

Functions

Builds a t/0 from a Plug.Conn's request headers.

Types

t()

@type t() :: %Phtmx.Request{
  boosted?: boolean(),
  current_url: String.t() | nil,
  history_restore?: boolean(),
  prompt: String.t() | nil,
  request?: boolean(),
  target: String.t() | nil,
  trigger: String.t() | nil,
  trigger_name: String.t() | nil
}

Functions

from_conn(conn)

@spec from_conn(Plug.Conn.t()) :: t()

Builds a t/0 from a Plug.Conn's request headers.

A request is considered an HTMX request when it carries HX-Request: true.