Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to render raw HTML code in Phoenix Framework?

I'm storing raw html from a contenteditable tag in my RethinkDB database. Now I want to display the content after retrieving it.

html.eex

<div id="contentEditableText">
    <%= for %{"contentText" => contentText} <- @contentText.data do %>
      <div><%= "#{contentText}" %></div>
    <% end %>
</div>

I can sucessfully retrieve it, but it's displaying the raw html itself.

like image 348
mesosteros Avatar asked Jul 22 '15 10:07

mesosteros


People also ask

How do I display raw code in HTML?

What is required to display Raw HTML code on a Webpage? In order to display HTML code on a webpage, you need to get rid of start tag < and end tag > symbol of every tag in your HTML code.

How do I render raw HTML in Blazor?

Raw HTML can be rendered in Blazor by using the MarkupString. You can set the raw HTML as a string to any parameter and cast it in a markup string.

How do I render a string in HTML?

append(html); When this code runs, the refer_summary variable actually contains a string which may contain HTML tags such as <b> , <i> etc., however, those tags are displayed on the page instead of rendering their behavior. For example, on the page it would show <b> rather actually making the content bold.


1 Answers

The phoenix_html library provides a raw/1 function for this case. phoenix_html is included by default so you should just need to do:

<div id="contentEditableText">
    <%= for %{"contentText" => contentText} <- @contentText.data do %>
      <div><%= raw(contentText) %></div>
    <% end %>
</div>
like image 144
Gazler Avatar answered Oct 03 '22 17:10

Gazler