rio517
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 phx.gen.live 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}
else
{:ok, assign(socket, page: "loading")}
end
end
def render(%{page: "loading"} = assigns) do
~L"<div>Loading...</div>"
end
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!
-Mario
Marked As Solved
LostKobrakai
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.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance










