yura
yura

Reputation: 14645

Import statment in Scala Play Framework doesn't work

I have the following code:

@(data: model.FrontPageData, list:List[model.FrontPageData])(
  implicit
  params:play.mvc.Scope.Params,
  flash:play.mvc.Scope.Flash,
  errors:Map[String,play.data.validation.Error]
)

@import controllers._
 <html>
 <head>
     <title>some title</title>
 </head>
 <body>
 ....

And Play Framework returns this error:

The file /app/views/Application/frontPageEditor.scala.html could not be compiled. Error raised is : illegal start of simple expression

on line @↓import controllers._

Upvotes: 9

Views: 6960

Answers (2)

yura
yura

Reputation: 14645

It is parsing bug on windows systems, based on play framework support response. On linux systems it works. Hope they will fix it soon on windows.

Upvotes: 2

Pere Villega
Pere Villega

Reputation: 16439

You can't use import statements from a template in the middle of the code, it's a limitation in Play templates. You must put them at the beginning of the template, as per documentation.

You can use fully qualified names though. In you case, if you have controller XController, do:

controllers.XController.method() 

to access it

(Edited after comments)

Upvotes: 6

Related Questions