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}
不會。