templates - Play 2 : How to compare strings in scala template?

标签 templates scala playframework-2.0

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

我正在尝试这个,但它不起作用

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

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

最佳答案

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

@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
}

关于templates - Play 2 : How to compare strings in scala template?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12697969/

相关文章:

php - 读取非php文件中的php标签并执行

scala - 在迭代字符串、kmer 计数时返回 Map 列表的函数

scala - 将 play 2.2 应用程序移植到 2.3.2 版本时出错 (Scala)

scala - 如何对 Scala (2.12) 宏使用泛型?

json - Play/Scala JSON 解析中的 if 语句?

c++ - 如何在 C++ 中定义接受派生类成员函数指针作为参数的类方法?

go - 使用 Go 模板中的变量键访问映射值

c++ - static_assert 检查非模板类的模板构造函数中的值

java - 重新启动 Play 应用程序 Docker 容器导致 'This application is already running' - RUNNING_PID 未删除

java - Play Framework 2 在 Intellij IDEA 中运行 JUnit 测试