1

let's say I have this controller's Action:

def getPost = Action { implicit request => Ok(views.html.post("bla bla bla")) }

Now I have two layouts:

// baseLayout.scala.html:
@(title: String)(content: Html)(implicit req: RequestHeader)
<html>
  ...
  @content
  ...
</html>

And

// postLayout.scala.html:
@(title: String)(content: Html)(implicit req: RequestHeader)
@baseLayout(title) { // Error: Cannot find any HTTP Request Header here
  <h1>Post</h1>
  @content
}

then I have this template:

// post.scala.html
@(post: String)(implicit req: RequestHeader)
@postLayout("First post") {
  <div>@post</div>
}

This code does not compile. I get this error

Cannot find any HTTP Request Header here (See up)

It is like the implicit RequestHeader is successfully transmitted: from the Action to the post template, then from the post template to postLayout template.

But it is not transmitted from the postLayout template to the baseLayout template.

I am suspecting that it is due to the fact that in postLayout template, the implicit comes after the Html block, it might discard any implicit propagation. Apart from that I don't see any explication, I am completely lost.

acmoune
  • 1,655
  • 2
  • 13
  • 29
  • What happens if you use the req explicitly, like: `@baseLayout(title){ ...}(req)`?! You might want to have a look at the generated Scala files somewhere in `target/scala-2.1*/...`. – cbley Nov 29 '19 at 09:32
  • I have Error: `req is not defined`. Really bizarre, I can use the implicit req in postLayout, but if I try to pass it to baseLayout, I have a `req is not defined`. I even tried to define baseLayout like this: `@(title: String, req: RequestHeader)(content: Html)` , so I can call it like this: `baseLayout(title, req){...}`, still req is not defined. – acmoune Nov 29 '19 at 10:07
  • I will check the generated Scala files ... – acmoune Nov 29 '19 at 10:09
  • BTW, which Play version are you using? Just because, your example code works fine for me with 2.7.3. – cbley Nov 29 '19 at 10:17

0 Answers0