如何将原始html传递给Play框架视图? [英] How to pass raw html to Play framework view?
问题描述
我正在尝试将一个简单的URL传递给play框架应用程序中的视图,但是当作为字符串传递时,url中的&
将更改为& amp;
导致网址无效。
I'm trying to pass a simple URL to a view within a play framework app, however when passed as a string, the &
in the url is changed to &
which causes the URL to not work.
如果我将参数更改为Html,即 @(url:Srting)
到 @(url:Html)
,当我尝试传递时出现错误url as string to view.render()
method。
If I change the argument to Html, i.e @(url: Srting)
to @(url: Html)
, then I get an error when I try to pass the url as string to view.render()
method.
如何将url转换为Html并传递给它那个?
How can I convert the url into Html and pass it as that?
推荐答案
为了防止视图上的动态内容发生默认转义,你需要包装 String
with @Html(String)
function:
To prevent the default escaping that happens for dynamic content on views you need to wrap the String
with @Html(String)
function:
查看:
@(url: String)
<div class="myLink">
Go to: @Html(url) <br>
not to: @url
</div>
控制器:
public static Result displayLink(){
return ok(view.render("<a href='http://stackoverflow.com/'>Stack Overflow</a>"));
}
参见模板引擎页面上的更多信息(特别是最底部的Escaping部分)。
See The template engine page on the documentation for more info (specifically the "Escaping" section at the very bottom).
这篇关于如何将原始html传递给Play框架视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!