Does Playframework 2.0.x support in templat

2019-04-17 18:43发布

I wonder if play 2.0.3 and higher supports else if in views? I only read that one have to code that way: if {...}else{if{...}else{...}} cannot believe that.

7条回答
别忘想泡老子
2楼-- · 2019-04-17 19:40

No, it doesn't. It allows you only for if(condition) {then...} else {otherwise...}

For more possibilities you need to use Pattern Matching (similar to PHP's switch())

In this case _ is a default option.

Sample from previous version of Play Autheticate (now the same is done with reflections in the controller)

@(url: String, token: String, name: String)

@defining(lang().code) { langcode =>

    @langcode match {
        case "de" => {@_password_reset_de(url,token,name)}
        case "pl" => {@_password_reset_pl(url,token,name)}
        case _ => {@_password_reset_en(url,token,name)}
    }

}

So maybe best option for you will be resolving the condition in the controller and passing it as a param to the view?

查看更多
登录 后发表回答