Shared Template Library
I am trying to create a view that only stores multiple HTML blocks that can be used by other views. Wanted to know if something like this is possible:
In views.home.common.scala.html:
@component1 = {
some common html
}
@component2 = {
some other stuff
}
In views.home.sample.scala.html:
@(user:User)
import home._
@component1
@common.component2
No luck so far and I don't see anything like it in the examples, but the idea is covered in frequently used template cases .
+3
source to share
1 answer
I had the same problem. What I did was define a file for each shared block, and then imported a package containing all of those files.
For example:
In views.common.component1.scala.html:
<div>
Common component 1
</div>
In views.common.component2.scala.html:
<div>
Common component 2
</div>
In views.main.scala.html:
@(content: Html)
@import common._
<!DOCTYPE html>
<html>
<head></head>
<body>
@component1()
@component2()
</body>
</html>
+1
source to share