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

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

问题描述



我有这个:

  @var title:String =Home



<

 简单表达式的非法开始)在模板顶部声明,但它给了我这个错误: ,_display_(Seq [Any](/ * 3.2 * / var)),format.raw / * 3.5 * /(title:String =Home


解决方案

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

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


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

I have this:

@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天全站免登陆