Reputation: 2201
I can't find the way how to interpolate variable in reusable block. I've tried this without luck:
@headers = @{
page match {
case "home" => Map(
"title" -> "Welcome",
"description" -> "Welcome to our site")
case "profile" => Map(
"title" -> "@user.name - @site.name",
"description" -> "Hello @user.name")
}
}
@headers = @{
page match {
case "home" => Map(
"title" -> "Welcome",
"description" -> "Welcome to our site")
case "profile" => Map(
"title" -> user.name + "-" site.name,
"description" -> "Hello" + user.name)
}
}
Upvotes: 0
Views: 177
Reputation: 3963
You should pass your variables as parameter:
@headers(user:User,site:Site) = @{
page match {
case "home" => Map(
"title" -> "Welcome",
"description" -> "Welcome to our site")
case "profile" => Map(
"title" -> user.name + "-" site.name,
"description" -> "Hello" + user.name)
}
}
Note: I guessed what type user
and site
had. You need to changes those of course.
Have a look at the documentation: https://www.playframework.com/documentation/2.4.x/ScalaTemplates#Declaring-reusable-blocks
Upvotes: 1