Dhairyashil
Dhairyashil

Reputation: 189

how to assign value in scala conditionally in template of play2.1

I am doing some conditional coding in scala template. just tell me how to write following java logic into scala.html template.

String temp = "";
 if(!cityName.equals(temp)){
         temp=cityName;
    }
 else{
        //do something.. 
     }

Upvotes: 0

Views: 227

Answers (1)

biesior
biesior

Reputation: 55798

Scala views allows you to define some variables with @defining block (see Reausable values), however it doesn't allow you to re-assignate it, so your pseudocode won't work as expected.

In such case you need to write custom getter in your model, which will return a valid value, instead doing it with temporary values in the views. You can also access any static Java method which will process your incoming string according to some conditions.

I must to say, that I have no idea what exactly you want to achieve, however I think, that can be solved with solutions proposed above.

Upvotes: 1

Related Questions