我有一个主布局页面:
//layouts/main.scala.html
@(title: String)(content: => Html)(implicit flash: Flash)
<!DOCTYPE html>
<html>
<!-- .... -->
<body>
<h2>Here is the flash:</h2>
@views.html.layouts._flash(flash)
<section class="content">My super content: @content</section>
</body>
</html>
//layouts/_flash.scala.html
@(flash: Flash)
@flash.data.foreach { case (k, v) =>
key, value: (@k, @v)
}
还有一个控制器:
//controllers/Application.scala
def index = Action { implicit request =>
Ok(views.html.application.index())
}
并为它提供观点:
//application/index.scala.html
@layouts.main("Index") {
<h1>Index page</h1>
}
index.scala.html
的视图会抛出错误:
could not find implicit value for parameter flash: play.api.mvc.Flash
我试过了:
//application/index.scala.html
@(implicit flash: Flash)
@layouts.main("Index") {
<h1>Index page</h1>
}
它引起了另一个错误:
not enough arguments for method apply: (implicit flash: play.api.mvc.Flash)play.api.templates.HtmlFormat.Appendable in object index. Unspecified value parameter flash.
答案 0 :(得分:2)
尝试将您的观点更改为:
@()(implicit flash: Flash)
@layouts.main("Index") {
<h1>Index page</h1>
}
或将您的控制器更改为:
def index = Action { implicit request =>
Ok(views.html.application.index(request.flash))
}