Wrapping Phoenix img_tag with Phoenix link

The summer heat in Japan must be getting to me… I was looking through the online Phoenix documentation and looking for a nice way to wrap images with urls programmatically. The best I could come up was this:

<%= 
link to: (@category01[:url]) do 
  img_tag("holder.js/100px120?outline=yes&text=nuts")
end 
%>

Just wondering if there is a more idiomatic or cleaner way?

1 Like

link/2 should be able to handle safe-HTML while img_tag/2 does return safe-HTML, so the code below should work:

"holder.js/100px120?outline=yes&text=nuts"
|> img_tag()
|> link(to: @category01[:url])
4 Likes

Nice! :023: