Starlet9334

Starlet9334

Hologram compiler fails when adding stylesheet to <head> tag

Hello there,

I am playing with Hologram. I’ve set up a fresh Phoenix project and followed the Hologram installation guide.

I have created a main_layout.holo like this

<head>
    <title>{@page_title}</title>
    <Hologram.UI.Runtime />
</head>
<body>
    <slot />
</body>

At this stage, compilation works.

Now, I want to load the app’s style sheet and copied the corresponding line from root.html.heex like so

<head>
    <title>{@page_title}</title>
    <Hologram.UI.Runtime />
    <link phx-track-static rel="stylesheet" href={~p"/assets/css/app.css"} />
</head>
<body>
    <slot />
</body>

However, now the compilation fails:

Compiling 1 file (.ex)
    error: undefined function sigil_p/2 (expected HologramTutorial.MainLayout to define such a function or for it to be imported, but none are available)
    │
  4 │   prop :page_title, :string
    │   ^^^^^^^^^^^^^^^^^^^^^^^^^
    │
    └─ (hologram_tutorial 0.1.0) app/layouts/main_layout.ex:4: HologramTutorial.MainLayout.template/0


== Compilation error in file app/layouts/main_layout.ex ==
** (CompileError) app/layouts/main_layout.ex: cannot compile module HologramTutorial.MainLayout (errors have been logged)

Removing the <link> line makes the compilation work again.

For reference, this is my main_layout.ex

defmodule HologramTutorial.MainLayout do
  use Hologram.Component

  prop :page_title, :string
end

What might be going on here?

Thank you!

Marked As Solved

phcurado

phcurado

Try removing the sigil ~p from your template.

<link phx-track-static rel="stylesheet" href="/assets/css/app.css" />

or import the verified routes helper under your template file

defmodule MyApp.MainLayout do
  use Hologram.Component
  use MyAppWeb, :verified_routes
## ...
end

Then you will be able to use the sigil ~p. More info on phoenix routing guide

Also Liked

bartblast

bartblast

Creator of Hologram

Thanks for the solution, @phcurado!

I wanted to add some clarification for anyone who might encounter a similar issue in the future.

You can’t use Phoenix routing-related functionality (like the ~p sigil) in Hologram templates, as Hologram has a separate routing system due to fundamental architectural differences.

Instead of:
<link phx-track-static rel="stylesheet" href={~p"/assets/css/app.css"} />

The recommended approach in Hologram is:
<link rel="stylesheet" href={asset_path("assets/css/app.css")} />

Why asset_path/1? This helper function automatically appends a digest to the asset path for proper asset fingerprinting, which is essential for cache busting in production environments.

While importing verified routes as @phcurado suggested will technically make the compilation error go away, using asset_path/1 is the idiomatic way to handle static assets in Hologram templates.

Where Next?

Popular in Questions Top

9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
mathew4509
I have a list say x = ["23gh", "56kh", "97mh"] I would like to pass each element to Val in each iteration. Say, in iteration 1 -------...
New
Exadra37
Sometimes I want to check if the input into a function is not a blank string. My first approach: defmodule Example do def do_stuff(s...
New
wernerlaude
In AR this is so simple @articles = current_user.articles How to do in Ecto? def index(conn, _params) do current_user = conn.assig...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
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
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
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
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

We're in Beta

About us Mission Statement