Disable layout

Hi all

How to disable layout in the views?

Thanks

1 Like

https://hexdocs.pm/phoenix/Phoenix.Controller.html#put_layout/2

set value to false as docs say

5 Likes

Thanks so much.

You can also do it on a the render call itself, like I only want it off for one specific render, so:

render(conn, :spa, layout: false)
3 Likes

The answer didn’t explain how to disable the layout in the view, does anyone know?

Either use render(conn, :index, layout: false) or conn|> put_layout(false) |> render(:index)

2 Likes

If you are running a LiveVeiw app, you’ll likely have a plug :put_root_layout, {MyAppWeb.LayoutView, :root} in your browser pipeline.

In which case put_layout(false) will only disable the app layout, so you’ll have to use conn |> put_root_layout(false) to disable root layout.

You are probably looking to disable both, so you’ll need:

conn
|> put_layout(false)
|> put_root_layout(false)
|> render(...)

or shorter:

conn
|> put_root_layout(false)
|> render(..., layout: false)
2 Likes