在 Play2 Scala 模板中声明变量 [英] Declare variable in a Play2 scala template

查看:24
本文介绍了在 Play2 Scala 模板中声明变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何声明和初始化要在 Play2 Scala 模板中本地使用的变量?

How do you declare and initialize a variable to be used locally in a Play2 Scala template?

我有这个:

@var title : String = "Home"

在模板顶部声明,但它给了我这个错误:

declared at the top of the template, but it gives me this error:

illegal start of simple expression """),_display_(Seq[Any](/*3.2*/var)),format.raw/*3.5*/(""" title : String = "Home"

推荐答案

@defining("foo") { title=>
  <div>@title</div>
  ...
}

基本上,你必须包装你要使用它的块

basically, you have to wrap the block in which you are going to use it

这篇关于在 Play2 Scala 模板中声明变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆