재사용 가능한 블록에서 변수를 보간하는 방법을 찾을 수 없습니다. 나는 운없이 이것을 시도했다.
@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)
}
}
변수를 매개 변수로 전달해야합니다.
@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)
}
}
참고 : 나는 어떤 유형을 추측 user
했고 site
가지고 있었다. 물론 그것들을 변경해야합니다.
설명서를 살펴보십시오 : https://www.playframework.com/documentation/2.4.x/ScalaTemplates#Declaring-reusable-blocks
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다