Define a scala function in a play template

playframework, playframework-2.0, scala

Solution

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
    ""
}

Problem

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?

Original source

Related problems