Not understanding why my put_layout(false) does not remote the root.html layout?

Hi,

Retrying Elixir for the 4th time in the last 3 years, I think this time will be the “good” one.

So I’m still just playing around, and would need an explanation about why a fresh controller with the following action:

def index(conn, params) do
  conn
  |> put_layout(false)
  |> render("index.html", params: params)
end

I would expect my HTML from my templates/[controller-name]/index.html.eex to be the only HTML.

Instead it’s wrapped in what appears to be the root.html from templates/layout/root.leex.

When I remove the put_layout(false) I’m getting wrapped inside the app.html.eex layout, which is also wrapped in what appears to be root.html.leex.

Looking around for where this supposedly root.html would be set, and I’m not finding anything in “my” code, so I suspect this might be inside Phoenix, not really ready to dive into the source code yet, just prototyping.

From the documentation it seems the put_layout(false) should be the way to go to remove the layout template.

Any pointer would be appreciated.
Thanks

For support of phoenix_live_view there are now two levels of layout the root_layout and the existing layout. This is so that the layout part can be “live” as well. You need to set both to false to disable any layout.

4 Likes

Anyone landing here from search, this is the code you’ll have to use:

conn
|> put_layout(false) # disable app.html.eex layout
|> put_root_layout(false) # disable root.html.eex layout
|> render(...)

or shorter:

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