1)在你的榜样将“码”的扩展,因此,例如,对于蟒蛇模板生成器,你会怎么做:
templateTypes += ("py" -> "some.python.PythonFormat")
2)转义HTML字符的东西是some.lang.LangFormat
类,必须执行play.api.template.Format
类。这有以下两种方法:
/**
* A template format defines how to properly integrate content for a type `T` (e.g. to prevent cross-site scripting attacks)
* @tparam T The underlying type that this format applies to.
*/
trait Format[T <: Appendable[T]] {
type Appendable = T
/**
* Integrate `text` without performing any escaping process.
* @param text Text to integrate
*/
def raw(text: String): T
/**
* Integrate `text` after escaping special characters. e.g. for HTML, “<” becomes “&lt;”
* @param text Text to integrate
*/
def escape(text: String): T
}
所以你可以让escape
委托raw
如果你不想做任何转义。
就控制换行符而言,这是模板本身的一个方面,如果您在模板中放置换行符,它们将显示在结果中。因此,例如:
@if(foo) {
@bar
}
将有换行符,而:
@if(foo) {@bar}
不会。