ostap
Can I remove `app.html.heex` in favor of just `root.html.heex`?
I’m starting a new Phoenix project with Inertia. It only needs root.html.heex. Therefore, I deleted app.html.heex. Unfortunately, this error shows up upon deletion:
no "app" html template defined for ExampleWeb.Layouts (the module exists but does not define app/1 nor render/2)
Any ideas why this happens? Is there another place where app layout is used?
router.ex:
plug :put_root_layout, html: {ExampleWeb.Layouts, :root}
page_controller.ex:
defmodule ExampleWeb.PageController do
use ExampleWeb, :controller
def home(conn, _params) do
conn |> render_inertia("Home")
end
end
root.html.heex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="csrf-token" content={get_csrf_token()} />
<.inertia_title><%= assigns[:page_title] %></.inertia_title>
<.inertia_head content={@inertia_head} />
<link phx-track-static rel="stylesheet" href={~p"/assets/css/app.css"} />
<script type="module" defer phx-track-static src={~p"/assets/app.js"} />
</head>
<body>
{@inner_content}
</body>
</html>
Marked As Solved
ostap
Turns out this was due to mistakenly using an older Phoenix version - 1.7 instead of 1.8.
In 1.8, it’s totally possible to avoid app.html.heex.
Also Liked
LostKobrakai
If you’re not using LiveView I’d skip the root layout and use just “layouts”. Root layouts were only introduced because LiveView needed the split between layout parts handled by LV and all the html boilerplate around it.
ostap
Found another override.
Inside controller method of web module, from this:
layouts: [html: SubKitWeb.Layouts]
To this:
layouts: [html: {SubKitWeb.Layouts, :root}]
ostap
No, that would print the root layout twice. Is it not possible to have a single layout in Phoenix by design?
Last Post!
foobar
gotcha thanks, managed to solve it
in my case i have removed the layouts from the use Phoenix.Controller bits, but turns out i also need to remove the namespace args on it. looking it at the source, it is also used to derive the layout module
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









