Call play2 template with variable arguments of type Html

不问归期 提交于 2019-12-06 03:45:02

You can use a workaround:

Example call in a template file:

@TabsBuilder{
    <a>tab1</a>
}{
    <a>tab2</a>
}.map(tabs.apply)

The TabsBuilder:

package views.html

import play.api.templates.Html

class TabsBuilder(templates: Vector[Html]) {
  def apply(html: Html) = new TabsBuilder(templates :+ html)
  def map(f: Seq[Html] => Html) = f(templates)
}

object TabsBuilder {
  def apply(html: Html) = new TabsBuilder(Vector(html))
}

The TabsBuilder enables you to write the code like you would have a variable number of parameter lists.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!