crescentryoshi

crescentryoshi

Hello, so I’m trying to load images using the username of each post as part of the route where the profile pictures are, basically it’s this format.

assets/profilepics/username.png

I tried doing it like this <img src=“static_path(@conn, “/assets/profilepics/#{@posts.user.name}.png”) %>”></img>, but it didn’t do the trick. What would be the correct way to add the username to the section of the tag that requires it?

Showing Posts 1 to 10

NobbZ

NobbZ

For you see any errors or what do you see instead of the username in the generated HTML?

Also you haven’t <%= in your post, is that by accident or in your code as well?

crescentryoshi

crescentryoshi OP

In my code as well, I tried doing it with <%= as well but it still shows up as a broken image. And no error per se, just the broken image icon instead of the image in the path.

crescentryoshi

crescentryoshi OP

Also, I do show the user name in one of the posts sections, and it’s loaded fine, so the path not loading fine has to do with my syntax for the img src tag. I’m just not sure where, this is my first project with Phoenix/elixir and I’ve been having some troubles with syntax/logic while working on it.

NobbZ

NobbZ

Then please tell us how the generated HTML looks like. The syntax looks fine assuming you open the <%= correct.

crescentryoshi

crescentryoshi OP

<img src="static_path(@conn, " assets="" profilepics="" #{@posts.user.username}.png")%="">

It looks like this without the <%=, if I add the <%= I get an incomplete expression error.

== Compilation error in file web/views/thread_view.ex ==
** (TokenMissingError) web/templates/thread/show.html.eex:39: syntax error: expression is incomplete
(eex) lib/eex/compiler.ex:45: EEx.Compiler.generate_buffer/4
(eex) lib/eex/compiler.ex:54: EEx.Compiler.generate_buffer/4
(phoenix) lib/phoenix/template.ex:378: Phoenix.Template.compile/2
(phoenix) lib/phoenix/template.ex:186: anonymous fn/3 in Phoenix.Template.“MACRO-before_compile”/2
(elixir) lib/enum.ex:1899: Enum.“-reduce/3-lists^foldl/2-0-”/3
(phoenix) expanding macro: Phoenix.Template.before_compile/1
web/views/thread_view.ex:1: Forum.ThreadView (module)
(elixir) lib/kernel/parallel_compiler.ex:198: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/6

NobbZ

NobbZ

And how exactly does the code look like that generates this error and the wrong output? The first output clearly shows you are not using <%=, the error shows you are using it probably wrong.

crescentryoshi

crescentryoshi OP

<%=img src="static_path(@conn, "/assets/profilepics/#{@posts.user.username}.png")%>"> This would be the code that generates the error.

NobbZ

NobbZ

Only the elixir stuff needs to be in <%= %>:

<img src="<%= static_path(@conn, "/assets/profilepics/#{@posts.user.username}.png") %>">

On a first glance at least…

crescentryoshi

crescentryoshi OP

Sweet! That did it. Now the HTML looks like this <img src="/assets/profilepics/pmgbove.png">, still shows up a broken image icon but I’ll figure that one out. Thanks a lot!

UsamaHaide0786

UsamaHaide0786

<img src={image_url}>
thats how it worked for me

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews