niccolox

niccolox

Phoenix 1.6 custom layout for controller action? has it changed?

I assume something has changed in Phoenix 1.6 because now when I set a layout in say an edit controller action I get nested pages, i.e. the root has the custom layout page inside it.

This used to work

def index(conn, _params) do
  posts = Blog.list_posts()
  render(conn, "index.html",
    posts: posts,
    layout: {TeacherWeb.LayoutView, "blog.html"})
end

but now it’s nesting the blog.html layout page inside the root.html

what to do?

Marked As Solved

kartheek

kartheek

router has browser pipeline which sets root_layout:

  pipeline :browser do
    plug :accepts, ["html"]
    plug :fetch_session
    plug :fetch_live_flash
    plug :put_root_layout, {TeacherWeb.LayoutView, :root} #<- this one 
    plug :protect_from_forgery
    plug :put_secure_browser_headers
  end

If you want to override the root layout - then try using put_root_layout/2:

    conn
    |> put_root_layout({TeacherWeb.LayoutView, "blog.html"})
    |> render("index.html",  posts: posts)

Also Liked

dimitarvp

dimitarvp

It would be a better forum etiquette to mark @kartheek’s comment as the solution. You basically copied part of his comment and marked your copy as the solution.

niccolox

niccolox

fixed, thats for the feedback

niccolox

niccolox

thanks, thats the update I was looking for

Where Next?

Popular in Discussions Top

ricklove
I was just introduced to Elixir and Phoenix. I was told about the 2 million websocket test that was done 2 years ago. From my research, t...
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
lorenzo
Hey everone! I created a prototype for my app using Nodejs for the api. But the framework I chose wasnt great (in general theresnt any g...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40165 209
New
RudManusachi
What configs will make sense to put to runtime.exs? – A bit of how I configure apps: I have generic configs in config/config.exs, dev...
New
nunobernardes99
Hi there Elixir friends :vulcan_salute: In a recent task I was on, I needed to check in two dates which of them is the maximum and which...
New
fireproofsocks
I’ve been working on an Elixir project that has required a lot of scripting. I usually reach for Elixir because I like it more (and in th...
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
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
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

We're in Beta

About us Mission Statement