Phoenix.LiveView.Controller (Phoenix LiveView v0.17.5) View Source

Helpers for rendering LiveViews from a controller.

Link to this section Summary

Functions

Renders a live view from a Plug request and sends an HTML response.

Link to this section Functions

Link to this function

live_render(conn, view, opts \\ [])

View Source

Renders a live view from a Plug request and sends an HTML response.

Before rendering, the @live_module assign will be added to the connection assigns for reference.

Options

See Phoenix.LiveView.Helpers.live_render/3 for all supported options.

Examples

defmodule ThermostatController do
  use MyAppWeb, :controller

  # "use MyAppWeb, :controller" should import Phoenix.LiveView.Controller.
  # If it does not, you can either import it there or uncomment the line below:
  # import Phoenix.LiveView.Controller

  def show(conn, %{"id" => thermostat_id}) do
    live_render(conn, ThermostatLive, session: %{
      "thermostat_id" => id,
      "current_user_id" => get_session(conn, :user_id)
    })
  end
end