我正在尝试创建一个仅包含可被其他 View 使用的可重用 HTML block 的 View 。想知道这样的事情是否可行:
在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
到目前为止还没有任何运气,我在样本中没有看到任何类似的东西,但这个想法在 Template common use cases 中有介绍。 .
最佳答案
我遇到了同样的问题。我所做的是为每个公共(public) block 定义一个文件,然后导入包含所有这些文件的包。
例如:
在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>
关于scala - 通用模板库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9621637/