Elixir 如何将html添加到phoenixframework flash消息?

Elixir 如何将html添加到phoenixframework flash消息?,elixir,phoenix-framework,Elixir,Phoenix Framework,我在控制器中尝试了以下操作: conn |> put_flash(:info, "text with <a href=\"link\">twitter<\\a>" |> render "index.html" 也许有一个选择?(尽管建议不同)这是我在项目中所做的: defmodule MyApp.PageController do use MyApp.Web, :controller import Phoenix.HTML.Link def i

我在控制器中尝试了以下操作:

conn
|> put_flash(:info, "text with <a href=\"link\">twitter<\\a>"
|> render "index.html"

也许有一个选择?(尽管建议不同)这是我在项目中所做的:

defmodule MyApp.PageController do
  use MyApp.Web, :controller
  import Phoenix.HTML.Link

  def index(conn, _params) do
    conn
    |> put_flash(:info, ["Please, visit ", link("Twitter", to: "http://twitter.com"), "!"])
    |> render("index.html")
  end
end
请注意,当其中一个元素是的结果时,flash消息内容不是一个普通字符串,而是rater


希望有帮助

这个代码有错误吗?还是输出错误?还是别的什么?没有错,就是我输入的同一个字符串。没有转义的链接。你的意思是HTML被转义,你可以使用
=raw(get_flash(…)
插入未转义的内容,但是Pawel在下面给出的答案更适合这个特定的用例。
defmodule MyApp.PageController do
  use MyApp.Web, :controller
  import Phoenix.HTML.Link

  def index(conn, _params) do
    conn
    |> put_flash(:info, ["Please, visit ", link("Twitter", to: "http://twitter.com"), "!"])
    |> render("index.html")
  end
end