Wlofrevo Kcast
Wlofrevo Kcast

Reputation: 629

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)

Upvotes: 2

Views: 2130

Answers (2)

mapek
mapek

Reputation: 270

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.

Upvotes: 7

adis
adis

Reputation: 5951

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:

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>

}

Upvotes: 2

Related Questions