scala - 如何在 Play Framework 的 Twirl 中将隐式值从一个模板布局传递到另一个模板布局?
问题描述
假设我有这个控制器的动作:
def getPost = Action { implicit request => Ok(views.html.post("bla bla bla")) }
现在我有两种布局:
// baseLayout.scala.html:
@(title: String)(content: Html)(implicit req: RequestHeader)
<html>
...
@content
...
</html>
和
// postLayout.scala.html:
@(title: String)(content: Html)(implicit req: RequestHeader)
@baseLayout(title) { // Error: Cannot find any HTTP Request Header here
<h1>Post</h1>
@content
}
然后我有这个模板:
// post.scala.html
@(post: String)(implicit req: RequestHeader)
@postLayout("First post") {
<div>@post</div>
}
此代码无法编译。我收到这个错误
Cannot find any HTTP Request Header here (See up)
这就像隐式RequestHeader
成功传输:从模板Action
到post
模板,然后从post
模板到postLayout
模板。
但它不会从postLayout
模板传输到baseLayout
模板。
我怀疑这是因为在postLayout
模板中,隐式出现在Html
块之后,它可能会丢弃任何隐式传播。除此之外,我没有看到任何解释,我完全迷失了。
解决方案
推荐阅读
- javascript - modal con vueJS 显示,但我无能为力
- vba - VBA 过程在 O365 升级后不再编译
- java - 等待功能在 10 秒后给我一个错误
- python - 如何在 Pytorch 中使用相同数据在两个不同的 GPU 上训练两个模型?
- mysql - 如何消除联合以获得更好的mysql性能
- r - 我正在尝试通过引用对每台机器进行回归传递
- c# - 根据选定的 ComboBox 将 bool 值插入 MySQL
- javascript - 如何在 Openlayers6 中绘制 lineString
- kubernetes - “更新”Kubernetes RBAC 权限有什么作用?
- certificate - 如何从 Inno Setup 的 [Files] 部分取消对文件的签名?