0

I want to define this Java variable

int x = 0; 
x = x + 1;

How is it in Play Scala Template??

I already tried this for defining:

@import scala.Predef;
val x= 0

but I can't add the variable

4
  • 2
    Possible duplicate of Play! framework: define a variable in template? Commented Nov 10, 2015 at 6:14
  • @johny thank you but it didn't work and i dont want to use defining Commented Nov 10, 2015 at 6:23
  • If you dont want to use @defining, you could always do something like @var x=0; x=x+1 and later use variable x, which is the second answer in the linked question. Commented Nov 10, 2015 at 6:27
  • Why don't you want to use @defining? Is it about having too many indentations? If so, I think you shouldn't worry, because you should not need this kind of variables so often. It would be only a few. If you need more, then most probably you need to break apart your template into small pieces. Commented Nov 10, 2015 at 6:50

1 Answer 1

1

They should be on the same line

@import scala.Predef; val x= 0

Also, if it is a variable, you should use var not val.

So what you need is

@import scala.Predef; var x= 0

And for reassigning:

@(x = x + 1)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.