Phoenix live view link not working with dynamic element

717 Views Asked by At

I have code in an html.eex file that needs to render a series of links and I'm using this code currently,

<%= for item <- @links do %>
  <%= link(item, to: URI.parse(item))%>
<% end %>

However when this renders it just to an email it just puts it an tag with no href attached like <a> https://example.com </a>

How do a I get the href portion setup correctly so the link can be clickable?

I am looking at https://hexdocs.pm/phoenix_html/Phoenix.HTML.Link.html#link/2 to base my code off of.

1

There are 1 best solutions below

0
On BEST ANSWER

You can still use standard

<a class="tailwind for example" href={URI.parse(item)}>click me</a>

tag or add class to your link which is missing from your example to become clickable.

link("<hello>", to: "/world", class: "btn") will generate #=> <a class="btn" href="/world">&lt;hello&gt;</a>

the second is an example from the docs.