我找不到如何在可重用块中插入变量的方法。 我没试过就试过这个:
@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)
}
}
答案 0 :(得分:1)
您应该将变量作为参数传递:
@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
的类型。当然,你需要改变它们。
查看文档:{{3}}