Play framework template automatically imports models._ among other things

柔情痞子 提交于 2019-12-03 08:48:50

You're right, Play Framework automatically add some import statements to all templates.

You can find these "default imports" in the PlaySettings trait from Play source code : https://github.com/playframework/Play20/blob/2.1.x/framework/src/sbt-plugin/src/main/scala/PlaySettings.scala

If you need to, you can add some additional imports in the project settings defined in your Build.scala :

val main = PlayProject(appName, appVersion, appDependencies, mainLang = JAVA).settings( 
    templatesImport += "com.acme._"
)

As of Play 2.3 I use this line in build.sbt

TwirlKeys.templateImports ++= Seq("very.long.package._", "another.package._")
Jai

You can look up the file : https://github.com/playframework/playframework/blob/master/framework/src/sbt-plugin/src/main/scala/PlayImport.scala#L40

All those mentioned there are imported.

Additionally, templatesImport += "com.acme._" is enough in 2.2.X to import all the files from a package i.e. in the file build.sbt.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!