Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic parameter in Scala template for PlayFramework

I would like to do something like that.

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>

}

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

How can I do that ?

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

like image 596
Zofren Avatar asked Nov 25 '11 09:11

Zofren


1 Answers

You have to concatenate the Strings, just as it were normal Scala code (because it is):

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

Everything inside @() is treated as Scala code.

like image 200
Marius Soutier Avatar answered Nov 02 '22 15:11

Marius Soutier