Scala模板集变量

编程入门 行业动态 更新时间:2024-10-28 20:28:11
本文介绍了Scala模板集变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我是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模板集变量

本文发布于:2023-07-11 17:16:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1094811.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   模板   Scala

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!