2015-01-02 45 views
0

我在非播放SBT項目中使用Twirl,並定義模板:如何將呈現的模板輸出寫入文件?

hello.scala.html

<h1>Welcome hello world</h1> 

它能生成包含下面的代碼斯卡拉文件:

package html 

import play.twirl.api._ 
import play.twirl.api.TemplateMagic._ 

import io.github.freewind.feverblog._ 

/**/ 
object hello extends BaseScalaTemplate[play.twirl.api.HtmlFormat.Appendable,Format[play.twirl.api.HtmlFormat.Appendable]](play.twirl.api.HtmlFormat) with play.twirl.api.Template0[play.twirl.api.HtmlFormat.Appendable] { 

    /**/ 
    def apply():play.twirl.api.HtmlFormat.Appendable = { 
     _display_ { 
     Seq[Any](format.raw/*1.1*/("""<h1>Welcome hello world</h1>""")) 
     } 
    } 

    def render(): play.twirl.api.HtmlFormat.Appendable = apply() 

    def f:(() => play.twirl.api.HtmlFormat.Appendable) =() => apply() 

    def ref: this.type = this 
} 

返回類型render()apply()play.twirl.api.HtmlFormat.Appendable。我如何將它轉換爲字符串,以便我可以將它寫入文件?

+0

@Jacek,感謝編輯所有的英文錯誤,我真的很喜歡這個 – Freewind

回答

3

play.twirl.api.HtmlFormat.Appendable只是play.twirl.api.Html的一個類型別名,它有一個toString方法。

views.html.hello().toString