如何在Phoenix Framework中呈现原始HTML代码? [英] How to render raw HTML code in Phoenix Framework?
本文介绍了如何在Phoenix Framework中呈现原始HTML代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在RethinkDB数据库中存储来自contenteditable标签的原始html。
现在我想在取回内容后显示内容。
html.eex
< div id =contentEditableText>
<%= for%{contentText=> contentText}< - @ contentText.data do%>
< div><%=#{contentText}%>< / div>
<%end%>
< / div>
我可以成功检索它,但它显示原始html本身。
解决方案
phoenix_html
默认包含在内,因此您只需要执行以下操作:
< div id =contentEditableText>
<%= for%{contentText=> contentText}< - @ contentText.data do%>
< div><%= raw(contentText)%>< / div>
<%end%>
< / div>
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.
解决方案
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>
这篇关于如何在Phoenix Framework中呈现原始HTML代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文