我在 Play 中创建了一个新 Controller !框架。我想将静态文本放入 Scala 模板中,但我得到 <br />
(所有 html 语法)呈现为文本。我怎样才能做到这一点?
public class Application extends Controller {
public static Result index() {
String page_content = "<strong>Lorem </strong>Ipsum is simply dummy text of the<br /> printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
return ok(views.html.index.render(page_content, "index"));
}
}
最佳答案
您的函数index
正在将两个字符串
传递给您的 View 函数:
public static Result index() {
String page_content = "<strong>Lorem </strong>Ipsum is simply dummy text of the<br /> printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
return ok(views.html.index.render(page_content, "index"));
}
所以你的模板应该是这样的:
@(controllerHtml: String, title: String)
@main(title) {
@Html(controllerHTML)
}
请记住: 默认情况下,动态内容部分根据模板类型(例如 HTML 或 XML)规则进行转义。如果要输出原始内容片段,请将其包装在模板内容类型中。请参阅文档:http://www.playframework.com/documentation/2.2.x/JavaTemplates
关于java - 模板 playframework 中的 html 语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20421392/