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

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; ...
New
mgjohns61585
Could someone help me? I’m making my first elixir program, number guessing game. I can’t figure out how to convert the user’s guess from ...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
earth10
Hi, I’m just starting to build a side-project with Elixir and Phoenix and doing some basic test with Elixir alone. What strikes me is th...
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
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
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

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52774 488
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29703 241
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
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
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 43806 214
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
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement