代码之家  ›  专栏  ›  技术社区  ›  William Ross

Phoenix实时视图链接无法使用动态元素

  •  0
  • William Ross  · 技术社区  · 2 年前

    我在一个html.ex文件中有一段代码,需要呈现一系列链接,我目前正在使用这段代码,

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

    然而,当它只呈现给一封电子邮件时,它只会给它添加一个没有href的标签,就像 <a> https://example.com </a>

    如何正确设置href部分,以便可以单击链接?

    我在看 https://hexdocs.pm/phoenix_html/Phoenix.HTML.Link.html#link/2 以我的代码为基础。

    0 回复  |  直到 2 年前
        1
  •  1
  •   copser    2 年前

    您仍然可以使用标准

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

    将示例中缺少的类标记或添加到链接中,使其可点击。

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

    第二个例子来自 docs