Render alternative template when socket not-connected?

I want to render a loading template until the second mount is called on socket connection, but don’t quite follow the best way to do that.

I’ve been using to get a sample app going and basically have this:

# myapp_web/live/page_live.ex

def mount(_params, _session, socket) do
  if connected?(socket) do
    socket = socket
       |> assign(:steps, "blabla")
       |> assign(:activity_minutes, "blabla")
    {:ok, socket}
    {:ok, assign(socket, page: "loading")}


def render(%{page: "loading"} = assigns) do

I would have thought that render would have to use the default behavior if the method signature didn’t match - rendering myapp_web/live/page_live.html.leex. How do I force it to do so?

I see in the documentation, I should be able to call render SomeView, "child_template.html", assigns I was hoping I didn’t need to setup an empty “dead view” to achieve this result. Or am I mistaken?

Thanks in advance for any help you could offer!


There’s Phoenix.LiveView.connected?(socket), which is only true for websocket connections.

Yes, Thanks for the reponse! I’m actually using connected? on line 4 of my example above to evaluate which assigns to attach to the socket. After that, the render call is made. I want to render an inline template if the assigns has page: loading or go render the default template, myapp_web/live/page_live.html.leex. I cannot figure out how to get it to match and rnder myapp_web/live/page_live.html.leexin the second case.

You can either use manual render functions or the co-located template. Afaik there’s no good way to use both at the same time.