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

vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
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
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
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

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36654 110
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 44532 311
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

We're in Beta

About us Mission Statement