dstpierre

dstpierre

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

Marked As Solved

LostKobrakai

LostKobrakai

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.

Also Liked

seva

seva

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)

Where Next?

Popular in Questions Top

New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> somethi...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

Other popular topics Top

9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New

We're in Beta

About us Mission Statement