Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play exception: '{' expected but 'import' found

It throws me the exception for line 3. The thing is i have just these lines:

package controllers

import play.api._
import play.api.mvc._
import views._
import models._

object Application extends Controller {

  def index = Ok(views.html.index("grrr", "blabla"))

}

EDIT: index.scala.html

@import helper._

@main("Todo") {

    <h1>Hello World</h1>

}

I'm using play 2.2.0 on windows xp (with sbt)

like image 385
Wlofrevo Kcast Avatar asked May 26 '26 15:05

Wlofrevo Kcast


2 Answers

I think that problem is with yours line separator in IDE. I once change LF(Linux) to CR(Mac)(by mistake, not knowing that this has an impact on compilation) and struggle with the same problem. After changing to default sperator everything back to normal.

like image 83
mapek Avatar answered May 28 '26 07:05

mapek


The first line in Play! template is reserved for the signature definition. This is also mentioned in the Welcome screen when you create a new Play Application.

Beside the question why you import the helper._, I would do the following:

  1. Make the first line empty, or at least NO import statements.
  2. Run play clean
  3. After this it should work, I hope :-)

Further information:

  • Play framework template automatically imports models._ among other things
  • https://github.com/playframework/playframework/blob/1acfd1dc4264e7589876fb1f4ebf37e584ab8bc6/framework/src/play/src/main/scala/views/play20/welcome.scala.html#L81
  • If you know a bit scala (I don't yet): https://github.com/playframework/playframework/blob/9206bea8c9c88acdc6786ebb2554f081396e8f6a/framework/src/templates-compiler/src/main/scala/play/templates/ScalaTemplateCompiler.scala

EDIT: 2013.09.24 at 22:15

You are passing two arguments to your view template (views.html.index("grrr", "blabla")), (views are compiled to functions). So in your function (`index view') the first line SHOULD define the function signature (arguments). I think that you should write your template as:

@(firstString : String, secondString : String)

@import helper._

@main("Todo") {

    <h1>Hello World</h1>

}
like image 32
adis Avatar answered May 28 '26 06:05

adis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!