0
我有一个主布局页面:不能使用闪光灯的视图
//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
的视图会抛出一个错误:
我尝试这样做:
//application/index.scala.html
@(implicit flash: Flash)
@layouts.main("Index") {
<h1>Index page</h1>
}
而且它造成的另一个错误:您的控制器
@()(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.
您需要在某处提供**隐式定义的“Flash”对象 - 您已在模板中指出您想要一个,现在您需要在范围内编写一个方法(例如在您的控制器中),该方法返回一个'Flash' – millhouse