1
votes

I'm using Play 2.0.2 and I'm having a problem with implicit parameters in one particular view template setup. I'll describe it the best I can but it's not exactly trivial so I apologize in advance for any confusion.

Central to the issue is a template I have called "piece". piece takes these parameters:

@(piecesData: objects.PiecesDataRequest)(implicit content: Html)

The content parameter is implicit because I am calling this template from another template as well as from a controller. I could not find a way to explicitly pass "empty" Html to the piece template from the controller, however it works if I implicitly pass the content param. The template using piece is "pieceUploadModal" which takes these parameters:

@(piecesData: objects.PiecesDataRequest, 
  pieceData: objects.PieceDataRequest, dialogTitle: String)

and calls piece like this:

@pieces(piecesData){ [Html] }

Now I want to add a second implicit param to piece which changes its param list too:

@(piecesData: objects.PiecesDataRequest)(implicit content: Html, user: User)

and I assumed then that I would need to change the pieceUploadModal template params too:

@(piecesData: objects.PiecesDataRequest, 
  pieceData: objects.PieceDataRequest, dialogTitle: String)(implicit user: User)

And be good to go... however, I get an error that isn't very helpeful:

pieceUploadModal.template.scala:24: not enough arguments for method apply: 
(implicit      content: play.api.templates.Html, 
implicit user: models.User)play.api.templates.Html in object pieces.
[error] Unspecified value parameter user.
[error] """),_display_(Seq[Any]
(/*3.2*/views/*3.7*/.html.content.pieces(piecesData)/*3.39*/
{_display_(Seq[Any] (format.raw/*3.40*/("""

I have been trying to get this to work in many different ways for a couple of hours and done numerous internet searches to no avail. Any help would be appreciated.

As a last piece of information, I will add that the paradigm I'm using here of passing the user implicitly works with all of my other templates that are not using the implicit Html parameter, i.e. I believe that is the crux of the issue here.

1

1 Answers

0
votes

I could not find a way to explicitly pass "empty" Html to the piece template from the controller

Empty Html can be passed with Html(""), you can even define it as a default value.

But in the end you just have to listen to compiler - it never lies. From your comments I understand this is how you defined your template:

(piecesData: controllers.objects.PiecesDataRequest)(content: play.api.templates.Html)(implicit user: models.User)

and this is how you call it:

views.html.content.pieces(PiecesDataRequest( Piece.getPiecesForContentFeed(contentFeedID), contentFeedID), Html(""))

You define three parens, but you are calling only two. Do it like this:

Ok(
   views.html.content.pieces(
       PiecesDataRequest(Piece.getPiecesForContentFeed(contentFeedID), contentFeedID))(Html(""))
   )
)