3

我正在尝试创建一个仅包含可被其他视图使用的可重用 HTML 块的视图。想知道这样的事情是否可行:

在views.home.common.scala.html 中:

@component1 = {
  some common html
}
@component2 = {
  some other stuff
}

在views.home.sample.scala.html 中:

@(user:User)
import home._

@component1
@common.component2

到目前为止还没有任何运气,我在示例中没有看到任何类似的东西,但是模板常见用例中涵盖了这个想法。

4

1 回答 1

1

我遇到了同样的问题。我所做的是为每个公共块定义一个文件,然后导入包含所有这些文件的包。

例如:

在views.common.component1.scala.html 中:

<div>
    Common component 1
</div>

在views.common.component2.scala.html 中:

<div>
    Common component 2
</div>

在views.main.scala.html 中:

@(content: Html)

@import common._

<!DOCTYPE html>
<html>
    <head></head>
    <body>
        @component1()
        @component2()
    </body>
</html>
于 2012-03-24T22:26:16.710 回答