在Twirl[PlayFramework]中导入部分文件
我使用PlayFramework和Twirl生成一些使用swagger文件的类 我正试图将一个大文件拆分成小块,使其更易于维护。但是,当呈现文件时,将忽略包含其他文件内容的标记: bigFile.scala.txt:在Twirl[PlayFramework]中导入部分文件,playframework,twirl,Playframework,Twirl,我使用PlayFramework和Twirl生成一些使用swagger文件的类 我正试图将一个大文件拆分成小块,使其更易于维护。但是,当呈现文件时,将忽略包含其他文件内容的标记: bigFile.scala.txt: @(otherFile: String) { { "foo": "bar" }, @otherFile { "one": "two" } } { { "a": "b" }, } otherFile.scala.txt: @(ot
@(otherFile: String)
{
{
"foo": "bar"
},
@otherFile
{
"one": "two"
}
}
{
{
"a": "b"
},
}
otherFile.scala.txt:
@(otherFile: String)
{
{
"foo": "bar"
},
@otherFile
{
"one": "two"
}
}
{
{
"a": "b"
},
}
bigFile.template:
package com.telefonica.baikal.views.txt
import _root_.play.twirl.api.TwirlFeatureImports._
import _root_.play.twirl.api.TwirlHelperImports._
import _root_.play.twirl.api.Html
import _root_.play.twirl.api.JavaScript
import _root_.play.twirl.api.Txt
import _root_.play.twirl.api.Xml
import models._
import controllers._
import play.api.i18n._
import views.txt._
import play.api.templates.PlayMagic._
import play.api.mvc._
import play.api.data._
object bigFile extends _root_.play.twirl.api.BaseScalaTemplate[play.twirl.api.TxtFormat.Appendable,_root_.play.twirl.api.Format[play.twirl.api.TxtFormat.Appendable]](play.twirl.api.TxtFormat) with _root_.play.twirl.api.Template2[String,String,play.twirl.api.TxtFormat.Appendable] {
/**/
def apply/*1.2*/(otherFile: String):play.twirl.api.TxtFormat.Appendable = {
_display_ {
{
Seq[Any](format.raw/*1.21*/("""
"""),format.raw/*2.1*/("""{"""),format.raw/*2.2*/("""
"""),format.raw/*3.3*/("""{"""),format.raw/*3.4*/("""
"""),format.raw/*4.5*/(""""foo": "bar"
"""),format.raw/*5.3*/("""}"""),format.raw/*5.4*/(""",
"""),_display_(/*6.4*/otherFile),format.raw/*6.13*/("""
"""),format.raw/*7.3*/("""{"""),format.raw/*7.4*/("""
"""),format.raw/*8.5*/(""""one": "two"
"""),format.raw/*9.3*/("""}"""),format.raw/*9.4*/("""
"""),format.raw/*10.1*/("""}"""),format.raw/*10.2*/("""
"""))
}
}
}
渲染文件:
{
{
"foo": "bar"
},
{
"one": "two"
}
}
有没有办法将de-other文件渲染到大文件中?关于
bigFile.scala.txt
的几个问题:
@(otherFile2: String)
{
{
"foo": "bar"
},
@otherFile2,
@otherFile(),
{
"one": "two"
}
}
- 参数
是一个字符串,用于隐藏同名模板otherFile
- 要将模板包含到另一个模板中,请使用括号。若包含方括号且未重命名输入参数,则可能无法编译
bigFile.scala.txt
:
@(otherFile2: String)
{
{
"foo": "bar"
},
@otherFile2,
@otherFile(),
{
"one": "two"
}
}
在控制器中的某个位置:
结果应该如下所示:
{
{
"foo": "bar"
},
{"x": "y"},
{
{
"a": "b"
},
},
{
"one": "two"
}
}