`identifier' expected but `' found Compilation error with Play 2.1 template

2,666 views
Skip to first unread message

Heath

unread,
Mar 9, 2013, 1:08:01 AM3/9/13
to play-fr...@googlegroups.com
I am new to Play and Scala. Overall the tutorial is pretty good but when I got to the templates I got stuck on a very cryptic error message. I am running the helloworld example and it keeps failing with the following error on the first line of the template:

`identifier' expected but `' found

This is the template it is failing on:

@(name: String, repeat: Int, color: Option[String])

@main("Here is the result:") {

    <ul style="color: @color.getOrElse("inherited")">
        @for(_ <- 1 to repeat) {
            <li>Hello @name!</li>
        }
    </ul>

    <p class="buttons">
        <a href="@routes.Application.index">Back to the form</a>
    </p>

}

I am using Scala 2.1 and Play 2.1.  Any ideas what this error means?  This is taken from the hellowork example that comes with Play 2.1.


Heath

unread,
Mar 9, 2013, 5:40:26 PM3/9/13
to play-fr...@googlegroups.com

More details on my issue.  I did not change anything in the sample code. Thanks for your help.

Main view below:

@(title: String)(content: Html)
<!DOCTYPE html>
<html>
    <head>
        <title>@title</title>
        <link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/main.css")">
        <link rel="shortcut icon" type="image/png" href="@routes.Assets.at("images/favicon.png")">
        <script src="@routes.Assets.at("javascripts/jquery-1.6.4.min.js")" type="text/javascript"></script>
    </head>
    <body>

        <header>
            <a href="@routes.Application.index">@title</a>
        </header>

        <section>
            @content
        </section>

    </body>
</html>

Console Exception:

! @6dhjgk32b - Internal server error, for (GET) [/] ->

sbt.PlayExceptions$TemplateCompilationException: Compilation error[`identifier' expected but ` ' found]
        at sbt.PlayCommands$$anonfun$43.apply(PlayCommands.scala:433) ~[na:na]
        at sbt.PlayCommands$$anonfun$43.apply(PlayCommands.scala:409) ~[na:na]
        at sbt.Scoped$$anonfun$hf5$1.apply(Structure.scala:581) ~[na:na]
        at sbt.Scoped$$anonfun$hf5$1.apply(Structure.scala:581) ~[na:na]
        at scala.Function1$$anonfun$compose$1.apply(Function1.scala:49) ~[scala-library.jar:na]
        at sbt.Scoped$Reduced$$anonfun$combine$1$$anonfun$apply$12.apply(Structure.scala:311) ~[na:na]
[warn] play - No application found at invoker init

routes

GET     /                           controllers.Application.index

Application.scala

/**
   * Describes the hello form.
   */
  val helloForm = Form(
    tuple(
      "name" -> nonEmptyText,
      "repeat" -> number(min = 1, max = 100),
      "color" -> optional(text)
    )
  )

  // -- Actions

  /**
   * Home page
   */
  def index = Action {
    Ok(html.index(helloForm))
  }

When I take out all template code ( using @ ) and have a text only template ( something with<h1>Hello</h1> for example ), I see no issues. Once I add template code using @ event if it is an unused code block like the following I get that error. I am using eclipse + Scala and Play plugin on Windows 7.

@sidebar = {
  <h1>Sidebar</h1>
}

Heath

unread,
Mar 10, 2013, 12:47:21 AM3/10/13
to play-fr...@googlegroups.com
figure this out.  The template files were not saved with UTF-8 encoding which seems to have been throwing off the compiler.  When I changed the encoding to UTF-8 all worked as expected.


On Saturday, March 9, 2013 12:08:01 AM UTC-6, Heath wrote:
Reply all
Reply to author
Forward
0 new messages