Reputation: 6952
I have an array of objects like so
[%{id:1, url:'image.jpg'}, %{id:2, url:'image2.jpg'}]
My phoenix template looks like so
<%= for item <- array() do %>
<div class="col-lg-4 col-sm-6">
<img class="img-fluid" src="<%= static_path(@conn, item.url ) %>" alt="">
</div>
<% end %>
Given that I'm already interpolating and pointing to my static path how do I interpolate twice or rather point to the image url after @conn
?
Thank you for your help!
Upvotes: 0
Views: 822
Reputation: 222198
You just need to prepend a /
to url
to make it work with static_path
. I'm assuming you have a double quoted String in the list as if you had single quote you'd be getting a different error. To prepend a /
, change:
static_path(@conn, item.url)
to
static_path(@conn, "/" <> item.url)
Upvotes: 1