Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile error in scala template while passing an arraylist: Not found value

I am trying to pass an arraylist to a scala template from a play controller.

In my controller

List<Profile> profiles = Profile.findAll();

return ok(contacts.render(profiles));

In the template contacts.scala.html

@import models.com.contactmanager.Profile
@(profiles: List[Profile])

I am getting the error:

not found: value profiles [error] 

for line

@(profiles: List[Profile])
like image 356
Pawan Avatar asked Feb 16 '23 11:02

Pawan


1 Answers

In Parameter lists of Scala templates you have to use the (a) fully qualified class name or (b) you import them in your Build.scala.

(a)

@(profiles: List[models.com.contactmanager.Profile])

(b)

//Play 2.2
val main = PlayProject(…).settings(
  templatesImport += "models.com.contactmanager.Profile"
)

For Play 2.3 the API changed: https://www.playframework.com/documentation/2.3.x/ScalaTemplates#Import-statements

TwirlKeys.templateImports += "models.com.contactmanager.Profile"
like image 196
Schleichardt Avatar answered May 02 '23 11:05

Schleichardt