7

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?

4
  • you can compare two strings with ==
    – Kim Stebel
    Oct 2, 2012 at 20:44
  • maybe it doesn't work because of the typo? no wait...typos
    – Kim Stebel
    Oct 2, 2012 at 20:45
  • didn't have the typo in the code, corrected the post Oct 2, 2012 at 20:46
  • with == i get '(' expected but ')' found. error message on the page! Oct 2, 2012 at 20:46

1 Answer 1

10

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
}
1
  • 4
    kind of annoying I had @if (sp.page....) instead of @if(... (the space between if and the ( is important apparently! Oct 2, 2012 at 21:01

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.