[英]How to render raw HTML code in Phoenix Framework?
I'm storing raw html from a contenteditable tag in my RethinkDB database. 我将来自contenteditable标记的原始html存储在我的RethinkDB数据库中。 Now I want to display the content after retrieving it.
现在,我想在检索内容后显示它。
html.eex 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. 我可以成功检索它,但它显示的是原始html本身。
The phoenix_html
library provides a raw/1 function for this case. phoenix_html
库在这种情况下提供了raw / 1函数。 phoenix_html
is included by default so you should just need to do: 默认情况下包括
phoenix_html
,因此您只需要执行以下操作:
<div id="contentEditableText">
<%= for %{"contentText" => contentText} <- @contentText.data do %>
<div><%= raw(contentText) %></div>
<% end %>
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.