myborobudur
myborobudur

Reputation: 4435

Define a scala function in a play template

I try to use a function in a play view template

@active(path: String):String = @{
       var active:String = ""
       if (request.path.startsWith(path)) {
           active = "class=\"active\""
       } 
       return active
}

<div class="container-fluid">
....
    <li @active("/page") ...>

The play compiler says that it can't find the value active. What's wrong here?

Upvotes: 9

Views: 5964

Answers (1)

Fynn
Fynn

Reputation: 4873

Try removing the return type of the function and move it to the top of your template. This works in my template (see also: Playframework 2.0 define function in View Template):

@active(path: String) = @{
  if (request.path.startsWith(path))
    "class=\"active\""
  else
    ""
}

Upvotes: 16

Related Questions