Phoenix Liveview render custom leex template

OK this time RTFM was the right thing to do. I mean Collocating templates. The problem is I didn’t know how to define the view needed.

So Just in case someone has the same problem as me. Define page_live_view.ex that contains:

defmodule AppWeb.PageLiveView do
  use AppWeb, :view

end

Now you can define template in templates/page_live/page_live.html.leex or render("page_live.html") inside page_live_view.ex. Your choice. To make it all work you need to define render/1 function inside your live view.

def render(assigns) do
    Phoenix.View.render(AppWeb.PageLiveView, "page_live.html", assigns)
end

Of course you can render different templates based on the data you have in assigns.