我一直在阅读Play上的文档!网站,并且看不到它解释了什么参数组以及它们将用于什么。玩!框架模板参数组
之间有什么区别:
@(title: String)(user: User)
和:
@(title: String, user: User)
如果有人可以帮助我在这里会不胜感激。
我一直在阅读Play上的文档!网站,并且看不到它解释了什么参数组以及它们将用于什么。玩!框架模板参数组
之间有什么区别:
@(title: String)(user: User)
和:
@(title: String, user: User)
如果有人可以帮助我在这里会不胜感激。
正如@mgosk在评论中所暗示的,多个参数列表是Scala函数的一个标准特性,Google可以回答得比我更好。
关于特别播放模板但是,它们非常有用。
TLDR在播放模板参数组是有用的:
一个原因是形式传递隐含参数的观点。隐参数是由编译器添加到呼叫现场,并作为spec points out他们必须在最后一个(或唯一的)参数列表中标明,例如:
@(title: String)(implicit request: RequestHeader)
<h1>@title</h1>
The path is for this request is <b>@request.path</b>.
当调用从一个动作你不认为模板只要有一个请求头(see here for more details on that),就不必明确提供请求头。
模板中多参数列表的另一个非常有用的用途是“包装”内容,尤其是考虑到可以用braces instead of parenthesis调用Scala函数。假设您有一些代表多个不同小部件的部分模板,但这些模板总是被相同的样板HTML包围。然后,您可以创建一个模板包装(称为widgetWrapper.scala.html
)是这样的:
@(name: String)(details: Html)
<div class="item">
<div class="item-name">@name</div>
<div class="item-body">
@details
</div>
</div>
这可以被调用,像这样:
@(item: WidgetA)
@widgetWrapper(item.name) {
<ul class="item-details">
<li>@item.detail1</li>
<li>@item.detail2</li>
</ul>
}
这最后的技术是如何定义标准化“页铬”或网站例如(文件standardLayout.scala.html
):
@(title: String)(content: Html)(sidebar: Html)
<html>
<head>
<title>@title</title>
</head>
<body>
<header>
<h1>@title</h1>
</header>
<article>@content</article>
<aside>@sidebar</aside>
</body>
</html>
使用像这样:
@()
@standardLayout("My Page on Goats") {
<p>
Lots of text about goats...
</p>
} {
<ul class="sidebar-links">
<li><a href="https://en.wikipedia.org/wiki/Goat">More about goats!</li>
</ul>
}
如您所见,两个大括号分隔的部分中的内容分别作为Twirl Html
传递给布局模板,分别作为主内容和边栏(将第一个参数中传递的标题作为字符串传递。)
由多个参数组使得这种操作变得可能。
请看此 http://stackoverflow.com/questions/4684185/why-does-scala-provide-both-multiple-parameters-lists-and-multiple-parameters-pe – mgosk