Question

I have a form object and I need to check if the value of a field is equal a certain string

I'm trying this but it is not working

 @if(sp.pageType.equals("customreCare")) {
   //render this specific div 
  } else {
   //render this other div
  }

but unfortunately it is not working, what is the syntax for that?

Was it helpful?

Solution

Use == operator for comparing strings:

@defining("something") {whatToTest =>
    @if(whatToTest == "something"){ There is something } else { There is.... nothing }
}

so in your case (of course make sure that there are no typos in the conditions like customreCare ...):

@if(sp.pageType == "customreCare") {
     //render this specific div 
} else {
     //render this other div
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top