ostap

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

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

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

ostap

Found another override.

Inside controller method of web module, from this:

layouts: [html: SubKitWeb.Layouts]

To this:

layouts: [html: {SubKitWeb.Layouts, :root}]
ostap

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

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

Where Next?

Popular in Questions Top

baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a &gt; b) do {:ok, "a"} end if (a &lt; b) do {:ok, b} end if (a == b) do {:ok, "equa...
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
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
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
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

Other popular topics Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31494 112
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

We're in Beta

About us Mission Statement