silverdr
Phoenix 1.6.6 phx.new puts some new plugs on top of router.ex these days. Those are:
plug :fetch_live_flash
plug :put_root_layout, {PhxApp.LayoutView, :root}
While I take (please somebody correct me if I am wrong) the first one to be an extended, direct replacement of fetch_flash/2, I am wondering what the use of the second one is. What problem it solves? What was not working well enough in 1.5 that this helps with?
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication):
toke...
New
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
New
** (ArgumentError) expected :max_attempts to be a positive integer, got: {:@, [line: 10, column: 19], [{:max_attempts, [line: 10, column:...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex










Showing Posts 1 to 6- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
kartheek
It puts
root.html.heexas root layout while rendering.You can also override if you want in controllers.
For Live Views, you can override in
live_sessionLive Layouts explains about this.
put_root_layout documentation
kokolegorille
It’s useful when You want to render in different format.
Sometime I need to render dynamic css, or files, or iframe…
I just need to switch which layout to use.
03juan
This was committed back in v1.4 branch so it’s been working well since then… Add root layouts (#3679) · phoenixframework/phoenix@a81dd86 · GitHub
silverdr
Yeah, but you don’t need the said plug in your router to do that, do you? I’ve been switching those as needed happily for some time but only now got to know about that
put_root_layout/2stuff.Might be. It’s just that I got it in my
router.exonly today, once I started migrating project to 1.6.Well, that’s what it says/implies
and that’s what the controller docs say. But after a few months of work on a sizeable project I don’t recall ever missing it in my
router.exor anywhere else for that matter. I’ve been happily usingapp.html.slimas my “root” layout all the time. The docs on Live Layouts shed some light on it though. I believe putting it there by default is another step into closer binding of both “live” and “dead” views, right?03juan
You don’t need it in the router in general but you have it right that it’s to bridge the gap between live and dead views. It helps to have a way to share the same root in a standard manner, so that the inital unconnected view of a live view can be rendered from the plug and you can set different pipelines to progressively upgrade the root layout. Or you can do progressive overrides e.g. the standard dead view gets a basic root, then a live session can set an upgraded root that pulls in the livesocket js stuff, and an admin live session can override the root with its own layout that may have other js which standard love views don’t need.
kartheek
Well, they chose the best possible name for the func
I migrated an old project from 1.4 to 1.6 - i was surprised by this new plug. It was in phx.new from 1.5 according to git. I messed up migration and it was rendering white pages, turns out this plug was missing from router.
These days I am finding more interesting information in phoenix_live_view docs.
Yes, Common things like js, css, title, etc which go in can be put in root.html.heex to eliminate duplication between live and dead views.