题
我正在尝试创建一个只能容纳可重用的HTML块,这些视图可以被其他视图使用。想知道是否有这样的东西:
在视图中.home.common.scala.html:
.
@component1 = {
some common html
}
@component2 = {
some other stuff
}
在视图中.home.sample.scala.html:
.
@(user:User)
import home._
@component1
@common.component2
到目前为止没有任何运气,我没有看到样本中的任何类似的东西,但是这个想法是覆盖在模板常用例。
解决方案
我有同样的问题。我所做的是为每个常用块定义一个文件,然后导入包含所有这些文件的包。
例如:
在Views.common.ponent1.scala.html: 中
.
<div>
Common component 1
</div>
在View.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>
不隶属于 StackOverflow