播放2:如何比较scala模板中的字符串?

时间:2012-10-02 20:41:28

标签: templates scala playframework-2.0

我有一个表单对象,我需要检查一个字段的值是否等于某个字符串

我正在尝试这个,但它无法正常工作

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

但不幸的是它不起作用,那是什么语法?

1 个答案:

答案 0 :(得分:9)

使用==运算符来比较字符串:

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

所以在你的情况下(当然要确保在customreCare ...)等条件下没有拼写错误:

@if(sp.pageType == "customreCare") {
     //render this specific div 
} else {
     //render this other div
}
相关问题