English 中文(简体)
游乐框架中的在线变量 2.x 设想情况模板
原标题:Inline variable in the Play framework 2.x Scala template

How to create an inline variable in the Play framework 2.x Scala template? Path from the Play s guide is not clear to me:

@defining(user.firstName + " " + user.lastName) { fullName =>
  <div>Hello @fullName</div>
}
最佳回答

First you don t create a variable but a value meaning it s read only.

在你的例子中,你创建了一个价值<代码>fullName,可在曲线方括号内查阅。

@defining("Farmor") { fullName =>
  <div>Hello @fullName</div>
}

页: 1

在你的模板中界定全球可获取的价值,只是包括你 brackets的括号。

E.g.

@defining("Value") { formId =>
  @main("Title") {
    @form(routes.Application.addPost,  id -> formId) {
      @inputText(name = "content", required = true)
      <input type="submit" value="Create">
    }
  }
}

例如,您可使用<代码>formId。

问题回答

If you don t want to use the @defining syntax you can define a reusable block which will be evaluated every time you use it:

@fullName = @{
  user.firstName + " " + user.lastName
}

<div>Hello @fullName</div>

With this same syntax you can also pass arguments to the block: https://github.com/playframework/Play20/blob/master/samples/scala/computer-database/app/views/list.scala.html

从样本中抽取密码,很容易跨越你的碎块,那么你可以使用@fullName。 具有价值的变量:

user.firstName + " " + user.lastName




相关问题
How to flatten a List of different types in Scala?

I have 4 elements:List[List[Object]] (Objects are different in each element) that I want to zip so that I can have a List[List[obj1],List[obj2],List[obj3],List[obj4]] I tried to zip them and I ...

To use or not to use Scala for new Java projects? [closed]

I m impressed with Twitter and investigating to use Scala for a new large scale web project with Hibernate and Wicket. What do you think about Scala, and should I use it instead of Java? EDIT: And, ...

Why does Scala create a ~/tmp directory when I run a script?

When I execute a Scala script from the command line, a directory named "tmp" is created in my home directory. It is always empty, so I simply deleted it without any apparent problem. Of course, when I ...

Include jar file in Scala interpreter

Is it possible to include a jar file run running the Scala interpreter? My code is working when I compile from scalac: scalac script.scala -classpath *.jar But I would like to be able to include a ...

Scala and tail recursion

There are various answers on Stack Overflow which explain the conditions under which tail recursion is possible in Scala. I understand the limitations and how and where I can take advantage of tail ...

热门标签