如何在带有 Playframework 2.2.x 的 build.sbt 中使用 templatesImport [英] How to use templatesImport in build.sbt with Playframework 2.2.x

查看:22
本文介绍了如何在带有 Playframework 2.2.x 的 build.sbt 中使用 templatesImport的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在我的所有模板中导入一些可重用的块.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆