我是Scala的新手(Play 2框架中的Scala模板),我想执行以下操作:传递参数isEdit并根据此参数定义一个值,伪代码:
I am new to Scala (Scala templates in Play 2 framework), I want to do the following: Pass a parameter isEdit and depending on this parameter, define a value, Pseudocode:
variable myTitle; if(isEdit) myTitle="edit question"; else myTitle="create question";如何在Play 2.0的Scala模板中制定此规则?传递isEdit并不是问题,仅创建新变量myTitle.谢谢:-)
How to formulate this in a Scala Template in Play 2.0? Passing isEdit is not the problem, only creating the new variable myTitle. Thanks :-)
推荐答案首先,查看Playframework文档,因为那里有很多关于模板的信息. www.playframework/documentation/2.0.4/ScalaTemplates
First of all, look over the Playframework documentation as there's a lot of good info on templates there. www.playframework/documentation/2.0.4/ScalaTemplates
现在,如果需要在整个模板中重用该值,则可以在模板顶部声明它(可能在任何@import之后):
Now, if you need to reuse the value throughout the template then you can declare it at the top of your template (probably after any @imports):
@myTitle = @{ if(isEdit) "edit question" else "create question" }如果只需要一个地方,那么实际上只需要if-else块:
If you only need it in one spot then you really just need the if-else block:
<h1> @if(isEdit) { edit question } else { create question } </h1>更多推荐
Scala模板集变量
发布评论