【问题标题】:Play Template Engine: how to pass an implicit parameter播放模板引擎:如何传递隐式参数
【发布时间】:2013-02-16 08:21:29
【问题描述】:

我正在尝试将隐式参数传递给 Play 模板...下面是我的代码:

test.scala.html:

@(implicit request: RequestHeader)

@()(implicit p = Some(controllers.routes.MyController.myActionMethod().absoluteURL))
@main("My Title") {

    // some HTML here...
}

main.scala.html:

@(title: String)(implicit request: RequestHeader, p: Option[String])

<html>
    ...
</html>

p 从未被分配...而且我总是收到错误消息could not find implicit value for parameter p。我错过了什么吗?谢谢。

【问题讨论】:

    标签: playframework playframework-2.0


    【解决方案1】:

    我刚刚想出了如何让它工作:

    @(implicit request: RequestHeader)
    
    @defining(Some(controllers.routes.MyController.myActionMethod().absoluteURL)) { implicit p =>
    
        // now main is able to access p
        @main("My Title") {
        ...
    }}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-05-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-18
      • 1970-01-01
      相关资源
      最近更新 更多