Dynamic parameter in Scala template for PlayFramework

I would like to do something similar.

Here is the main template:

@(title: String)(content: Html)
<!DOCTYPE html>
<html>
    <head>
        <title>@title</title>
        <link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/main.css")">
        <link rel="shortcut icon" type="image/png" href="@routes.Assets.at("images/favicon.png")">
        <script src="@routes.Assets.at("javascripts/jquery-1.6.4.min.js")" type="text/javascript"></script>
    </head>
    <body>
        @content
    </body>
</html>

And here is another one:

@(user: User)

@main(title = "@user.email - SiteName") {

    <b>@user.email (@user.role)</b>

}

A later version does not work because it failed with the "@ user.email" parameter in the title parameter.

How can i do this?

PS: I know that I can do it differently (add "- SiteName" to the main template), but this is just an example to understand how Scala works.

+5
source share
1 answer

You should concatenate the lines, as it was in normal Scala code (because it is):

@main(title = user.email + " - SiteName") {
  <b>@user.email (@user.role)</b>
}

Everything inside is @()considered as a Scala code.

+6
source

All Articles