如何在带有 Playframework 2.2.x 的 build.sbt 中使用 templatesImport [英] How to use templatesImport in build.sbt with Playframework 2.2.x
问题描述
我必须在我的所有模板中导入一些可重用的块.
I have to import some reusable blocks in all my templates.
我在 appviewslocksheader.scala.html
中定义了一个块,以将该块包含在我的所有模板中(如 这里) 我在 build.sbt 中包含了这一行:
I have defined a block in appviewslocksheader.scala.html
, to include the block in all my templates (as described here) I have included in build.sbt this line:
templatesImport += "views.html.blocks._"
但是我有这个编译错误:
but I have this compilation error:
[error] E:workspaceplay2testappviewsadminmain.scala.html:13: not found: value header
[error] @header()
[error] ^
块没有导入,我要改什么?
the block is not imported, what I have to change?
请注意,如果我使用 @import blocks._
在模板中导入块,它会起作用.
note that if I import the block in the template with @import blocks._
it works.
推荐答案
我找到了解决问题的方法:在 build.sbt 中,我必须移动 templatesImport += "views.html.blocks._"
在 play.Project.playJavaSettings
行之后.
I have found the solution to my problem: In build.sbt I have to move the line templatesImport += "views.html.blocks._"
after the line play.Project.playJavaSettings
.
这是因为 playJavaSettings
使用默认导入初始化变量 templatesImport
.
This is due to the fact that playJavaSettings
initializes the variable templatesImport
with the defaults imports.
这篇关于如何在带有 Playframework 2.2.x 的 build.sbt 中使用 templatesImport的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!