Hypa.Phoenix (Hypa v0.4.0)

Copy Markdown View Source

Functions for using htmx with Phoenix applications.

Summary

Types

A dictionary with the assigns to be used in the view.

The name of a Phoenix template.

Functions

Renders several templates, concatenating the results.

Types

assigns()

(since 0.4.0)
@type assigns() :: Keyword.t() | map()

A dictionary with the assigns to be used in the view.

template()

(since 0.4.0)
@type template() :: binary() | atom()

The name of a Phoenix template.

Functions

render_many(conn, templates)

(since 0.4.0)
@spec render_many(Plug.Conn.t(), [template() | {template(), assigns()}]) ::
  Plug.Conn.t()

Renders several templates, concatenating the results.

Elements of the templates list can be atoms, strings, or tuples of an atom/string and a keyword list of assigns, which will be passed to the template.

This function does not render layouts, because it assumes you're using it to render htmx out-of-band swaps, which don't need layouts. This function also assumes that it is rendering HTML.

Examples

conn
|> Hypa.Phoenix.render_many([
  :foo,
  {:bar, [a: 1]},
  {"baz", [b: 2, c: 3]}
])