【发布时间】:2013-12-21 01:32:39
【问题描述】:
我想在我的模板中转义 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 分支的内容并留下
else {
<b>NotEmpty</b>;
}
打印效果很好。 我正在使用使用 Scala 2.10.2 构建的 play framework 2.2.1(运行 Java 1.7.0_25)
【问题讨论】:
-
只要用css把文字加粗就行了。
-
这不是让文本变粗,而是打印出 html 标签,例如:
some text
或some elements -
嗯只是好奇你为什么使用
for这样的循环?@for(appointment <- appointments)不是更好吗?也可以使用@if{}else{}等。尝试先转换为标准 Play 语法并检查这是否能解决您的问题 -
我不得不更改语法,因为我在块中声明了一个局部变量 -> @{val procedure =ointments(index).getProcedures()
-
那么
@defining(appointments(index).getProcedures()) { procedure => <b>@procedure</b> }呢?
标签: scala templates playframework