LiveView custom layout not rendered

Hello,
I have a custom layout for use in a pipeline as

 pipeline :admin_required do
 plug MyAppWeb.Plugs.AuthAdmin
 plug :put_root_layout, ...
 plug :put_layout,...

and plug it as

 scope "/admin" do pipe_through [:admin_required]
     get "/"...
     get "/data"... 
     live "/dashboard"...
 end

For the two get routes everything works fine, but for the live route the custom layout is not rendered, why please ?

Hi @Sidi_Mohammed - a bit more information is needed to provide you with any help. e.g. is an error displayed? Is there an error in the logs? What is your actual live "/dashboard"... definition? (i.e. what is “…”). What does the liveview code look like relating to the definition.

1 Like

Hi @mindok,
No erros are shown in the logs, the definition for my live routes are very simple, and all work fine except the rendering of the custom layout that didn’t work.
I tried to render it when mounting the socket and it was rendered, so I think maybe in LiveView this is the only way to render it

If I understand correctly you have one root and 2 layout lets call them app(the original) and admin

To decide with Live View will be using which layout you need to edit your MyappWeb.ex

The original is as follow, keep it as it is

def live_view do
    quote do
      use Phoenix.LiveView,
        layout: {MyappWeb.Layouts, :app}

      unquote(html_helpers())
    end
  end

Create a new one under

def live_view_admin do
    quote do
      use Phoenix.LiveView,
        layout: {MyappWeb.Layouts, :admin}

      unquote(html_helpers())
    end
  end

and then in your Admin Live View you do

  use MyappWeb, :live_view_admin
1 Like

Thank you @karim-semmoud for your help, this is exactly what I was looking for