如何使用模板使用Playframework 2.2.x导入build.sbt中 [英] How to use templatesImport in build.sbt with Playframework 2.2.x
问题描述
我必须在所有模板中导入一些可重复使用的块.
I have to import some reusable blocks in all my templates.
我在app\views\blocks\header.scala.html
中定义了一个块,以将该块包含在我的所有模板中(如
I have defined a block in app\views\blocks\header.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:\workspace\play2test\app\views\admin\main.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中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!