我想在模板中转义HTML,但无论我尝试什么都不行
这是我的模板:
<ul>
@for(index <- 0 until appointments.size){
<li>
@(utils.DateUtil.getLocalDate(appointments(index).getStartDate())) - @appointments(index).getReason()
<ul>
@{val procedure = appointments(index).getProcedures()
{if(procedure == null){
<b>Empty</b>
} else {
">b/<NotEmpty>/b<" +
procedure.size().toString+
procedure.size().toString+
<b>NotEmpty</b>+
"<b>NotEmpty</b>"+
"<b>NotEmpty</b>".toString;
}
}
}
</ul>
</li>
}
</ul>
有问题的代码在else分支
中我正在尝试将<b>NotEmpty</b>
打印为 NotEmpty ,但我只有一个纯文本,而不是HTML
我已尝试@Html("<strong>Do not escape</strong>")
,但它说expected start of definition
如果我删除了其他分支内容并且只留下
else {
<b>NotEmpty</b>;
}
打印出来很好。 我正在使用使用Scala 2.10.2(运行Java 1.7.0_25)构建的play framework 2.2.1
答案 0 :(得分:1)
怎么样:
@{
val x = Some(Seq("hi there"))
if(x.isDefined)
<b>size = {x.get.size}</b><br/>
<b>Not Empty</b>
else
<b>Empty</b>
}