Play Framework template not Html type

I have a template named mainBodywith the form:

@(title: String)(html: Html, moreScripts: Html = Html(""))

I can call it like

views.html.mainBody("All properties")(views.html.showProperties(list))

views.html.showProperties()- another template. I get the impression that templates are just functions that return Html. However, if I extend this to:

views.html.mainBody("All properties")(views.html.showProperties(list), views.html.showPropertiesScripts)

Where views.html.showPropertiesScriptsis just a template with some HTML code, I get an error:

play.PlayExceptions$CompilationException: Compilation error[type mismatch;
 found   : views.html.showPropertiesScripts.type
 required: play.twirl.api.Html]
        at play.PlayExceptions$CompilationException$.apply(PlayExceptions.scala:27) ~[na:na]
        at play.PlayExceptions$CompilationException$.apply(PlayExceptions.scala:27) ~[na:na]
        at scala.Option.map(Option.scala:145) ~[scala-library-2.11.2.jar:na]
        at play.PlayReloader$$anon$1$$anonfun$play$PlayReloader$$anon$$taskFailureHandler$1.apply(PlayReloader.scala:234) ~[na:na]
        at play.PlayReloader$$anon$1$$anonfun$play$PlayReloader$$anon$$taskFailureHandler$1.apply(PlayReloader.scala:229) ~[na:na]

I do not understand this. Instead of the expected type Html, views.html.showPropertiesScriptsis there views.html.showPropertiesScripts.type? What is it and why views.html.showPropertiesScriptsnot type Html(like my other templates)?

+4
source share
2 answers

, "" " ". views.html.showPropertiesScripts - , ( @()). , Html, def apply(): Html, , , Html. () => Html. :

views.html.mainBody("All properties")(views.html.showProperties(list), views.html.showPropertiesScripts())

. apply, , , Scala , apply.

+1

mainBody.scala.html:

@(title: String, moreScripts: Html = Html(""))(html: Html)
<!DOCTYPE html>
<html>
    <head lang="en">
      <title>@title</title>
      @moreScripts
    </head>
    <body>
       @html
    </body>
</html>

:

@(list: List[YourType])

@moreScripts = {
    <script>alert ('it works')</script>
}

@mainBody(title = "All properties", moreScripts = moreScripts) {
    @showProperties(list)
}

moreScripts , :

@(list: List[YourType])

@mainBody(title = "Other view") {
    @showProperties(list)
}
+3

All Articles