Passing temporary variable to template

24 views
Skip to first unread message

era.ch...@mindparabole.com

unread,
Aug 13, 2017, 7:56:39 PM8/13/17
to Play Framework
I have created a temporary variable "count" type int inside controller to hold the result of a method.I am trying to pass that to view "queryResult".I am using " return Results.ok(views.html.queryResult.render(count);",it shows an error "render() in queryResult can not be applied to  (int)".Any help appreciated.

Igmar Palsenberg

unread,
Aug 14, 2017, 2:25:00 PM8/14/17
to Play Framework


Op maandag 14 augustus 2017 01:56:39 UTC+2 schreef era.ch...@mindparabole.com:
I have created a temporary variable "count" type int inside controller to hold the result of a method.I am trying to pass that to view "queryResult".I am using " return Results.ok(views.html.queryResult.render(count);",it shows an error "render() in queryResult can not be applied to  (int)".Any help appreciated.

Convert it to a String I would say.


Igmar 

Justin du coeur

unread,
Aug 14, 2017, 4:18:16 PM8/14/17
to play-fr...@googlegroups.com
Shouldn't be necessary.  The question I have is, where does ".render" come from?  Is this a Java thing?  I've never encountered it in the Scala API, and I'm wondering how it's defined.  At least on the Scala side, it's all about making sure that the parameters in the signature of the template (the first line) match the arguments you're passing in to it...

Rich Dougherty

unread,
Aug 14, 2017, 7:07:28 PM8/14/17
to play-framework
For more insight into how Twirl works you can take a look at the code it generates in the target folder, e.g. target/scala-2.12/twirl/main/views/html/index.template.scala.

– Rich

--
You received this message because you are subscribed to the Google Groups "Play Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framework+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/CAO26FW1FRyT1gXZpqRwsCTtPMjkr_9xDPgDyJTpBcmb0e2COmg%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.



--
Rich Dougherty
Engineer, Lightbend, Inc

Justin du coeur

unread,
Aug 15, 2017, 9:45:22 AM8/15/17
to play-fr...@googlegroups.com
So render() is simply a synonym for apply()?  That's what I'm getting from looking at the generated code.

In which case, it confirms my point to the original poster: you need to rewrite queryResult.scala.html so that it takes an Int.  Probably all you need to do is alter the first line of the template...

Reply all
Reply to author
Forward
0 new messages