0

我正在尝试从视图中调用主布局(就像在docs中一样),但出现错误:

 [error] C:\Users\Marco\Documents\Devel\Java\DroversWeb\app\views\device\list.sca
la.html:1: too many arguments for method apply: ()play.twirl.api.HtmlFormat.Appe
ndable in object _layout
[error] @views.html.shared._layout("User")
[error]                           ^
[error] C:\Users\Marco\Documents\Devel\Java\DroversWeb\app\views\shared\_layout.
scala.html:1: not found: value title
[error] ?@(title: String)
[error]    ^
[error] two errors found
[error] (compile:compile) Compilation failed
[error] Total time: 34 s, completed 29-gen-2015 16.27.59

这是我尝试使用的代码: CONTROLLER

public static Result list() {
        return ok(views.html.device.list.render());
    }

列表显示

@views.html.shared._layout("User")

** _布局 **

@(title: String)
<!DOCTYPE html>
<html lang="en">
<head>
....
</html>

** 构建.SBT

...

lazy val root = (project in file(".")).enablePlugins(PlayJava)

scalaVersion := "2.11.5"

libraryDependencies ++= Seq(
  "org.webjars" %% "webjars-play" % "2.3.0-2",
  "org.webjars" % "bootstrap" % "3.3.1",
  "org.webjars" % "jquery" % "2.1.1",
  "org.webjars" % "pace" % "1.0.2",
  "org.webjars" % "font-awesome" % "4.2.0",
  "org.webjars" % "jquery-ui" % "1.11.2",
  javaJdbc,
  javaEbean,
  cache,
  javaWs,
  "org.mongodb" % "mongo-java-driver" % "2.12.5",
  "org.mongodb.morphia" % "morphia" % "0.109",
  "org.mongodb.morphia" % "morphia-logging-slf4j" % "0.109",
  "org.mongodb.morphia" % "morphia-validation" % "0.109",
  "be.objectify"  %% "deadbolt-java"     % "2.3.2",
  "com.feth"      %% "play-authenticate" % "0.6.8"
)

** 插件.SBT **

resolvers += "Typesafe repository" at "https://repo.typesafe.com/typesafe/releases/"
// The Play plugin
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.3.7")
// web plugins
addSbtPlugin("com.typesafe.sbt" % "sbt-coffeescript" % "1.0.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-less" % "1.0.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-jshint" % "1.0.1")
addSbtPlugin("com.typesafe.sbt" % "sbt-rjs" % "1.0.1")
addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.0.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-gzip" % "1.0.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-mocha" % "1.0.0")

代码有什么问题?

我也尝试了(content: Html) in _layout 和 list.scala.html 中的 html 代码,但编译器总是在之后@(停止not found: value title

如果我删除布局中的参数并使用@views.html.shared._layout()它调用它会正确编译。

4

1 回答 1

0

通过问题编辑解决 - 转换为社区 wiki 答案。

OP写道:

从头开始我现在有一个能够编译的项目......一切都是一样的,我一个一个地复制文件以找出问题,但到目前为止没有问题。使用 winmerge,我查看了文件夹,我可以看到,在 target\scala-2.11\twirl....\shared_layout.template.html 中,工作的是:

/**/
object _layout extends BaseScalaTemplate[play.twirl.api.HtmlFormat.Appendable,Format[play.twirl.api.HtmlFormat.Appendable]](play.twirl.api.HtmlFormat) with play.twirl.api.Template1[String,play.twirl.api.HtmlFormat.Appendable] {

  /**/
  def apply/*1.2*/(title: String):play.twirl.api.HtmlFormat.Appendable = {
      _display_ {

不工作的是:

/**/
object _layout extends BaseScalaTemplate[play.twirl.api.HtmlFormat.Appendable,Format[play.twirl.api.HtmlFormat.Appendable]](play.twirl.api.HtmlFormat) with play.twirl.api.Template0[play.twirl.api.HtmlFormat.Appendable] {

  /**/
  def apply():play.twirl.api.HtmlFormat.Appendable = {
      _display_ {

我从原始项目中删除了 _layout 文件,复制了新的文件(从 winmerge 的角度来看是相同的),现在它可以工作了。

于 2015-04-26T18:36:40.950 回答