Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play Framework - Using Javascript Variable in Scala Template

So I have something that looks like this:

<script>
$(document).ready(function(){
  $("button.fadeMeOut").click(function(){
      var fadeID = $(this).attr('id');
      window.location.href = '@routes.Application.function(fadeID)';
  });
});
</script>

Of course this code will give a not found: value fadeID error. Is there a way for me to do something like this in Play Scala template?

like image 312
cYn Avatar asked Jul 23 '13 17:07

cYn


2 Answers

You can not mix Scala variables (server-side) with JS variables (client-side) as they are generated in quite distant environments.

Instead you can use for an example Play's javascriptRoutes like described in other question

like image 173
biesior Avatar answered Sep 18 '22 01:09

biesior


You can insert the relative URL in place of '@routes.Application....etc'

So for example "/function/" + fadeID

If the route of @routes.Application.function is /function

like image 38
Daniel Langer Avatar answered Sep 20 '22 01:09

Daniel Langer