Put_flash html not working as desired

Hi all,
My put_flash message include html text.
but it will direct to display same text in my page test01, no show the line breaks.
How can i change my code?
Thanks.
|> put_flash(:info, "test01 <br /> test02 <br /> test03 <br /> test04") |> redirect(to: home_path(conn, :index))

1 Like

Probably this…
https://hexdocs.pm/phoenix_html/Phoenix.HTML.html#raw/1

2 Likes

Thanks for reply quickly. it work.:joy:

Hi all,
I set struct to put_flash(:info, %{error_msg: error_msg, value: value}),
How can i get it in html or javascript?

i doing like this, but alway get the error message
protocol Phoenix.HTML.Safe not implemented for %{error_msg:…

var test = ‘<%= get_flash(@conn, :info) %>’
console.log(test);

Thanks all. Solved

I would just clarify that put_flash accepts a list, where each element can optionally be raw. Here is an example warning message with an HTML break and followed by a live_redirect link/button.

  put_flash(
      socket,
      :warning,
      [
        "You need to do something",
        raw("<br />"),
        live_redirect("Click Here", to: Routes.author_new_path(socket, :new))
      ]
)