Define scala function in a playback template

I am trying to use a function in a playback preview 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 playback compiler says that it cannot find the value active. What is wrong here?

+8
scala playframework
source share
1 answer

Try removing the return type of the function and moving it to the top of your template. This works in my template (see Also: The Playframework 2.0 function defines in the View Template ):

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

All Articles