【问题标题】:Pass parameter to parent or sub template将参数传递给父模板或子模板
【发布时间】:2012-05-23 14:41:12
【问题描述】:

在我的索引方法中,我呈现了一个基本的登录表单,我将其发送到我的 index.scala.html

/**
 * Main entry method for the application
 */
public static Result index() {
     return ok(views.html.index.render(form(Application.Login.class)));
}

index.scala.html文件中:我已经定义了form参数:

@(form: Form[Application.Login])

@main(title = "myTitle") {
    <h2>Testing app</h2>
}

因此,在这个文件中,我通过 @main(...) 调用父模板。但是如何将 form 传递给我的父模板?我尝试了以下方法:

@(form: Form[Application.Login])

@main(title = "myTitle", form) {
    <h2>Testing app</h2>
}

以及在我的 ma​​in.scala.html 中:

@(title: String, form: Form[Application.Login])(content: Html)

但这不起作用,我收到以下错误消息:

not enough arguments for method apply: (title: java.lang.String, form: play.data.Form[controllers.Application.Login])(content: play.api.templates.Html)play.api.templates.Html in object main. Unspecified value parameter form.

【问题讨论】:

  • 这可能是由于使用了命名参数而导致的问题。试试@main(title = "myTitle", form = form) { … } 或只是@main("myTitle", form) { … }
  • 朱利安,是的,它正在工作。只需要清理和运行我的应用程序。谢谢

标签: playframework-2.0


【解决方案1】:

正如 Julien 所说,这是可行的:

@main(title = "myTitle", form = form) { … } or just @main("myTitle", form) { … } 

【讨论】:

    猜你喜欢
    • 2010-12-26
    • 1970-01-01
    • 2015-08-05
    • 1970-01-01
    • 1970-01-01
    • 2011-09-14
    • 1970-01-01
    • 2019-02-15
    相关资源
    最近更新 更多