문제
다른 뷰에서 사용할 수있는 재사용 가능한 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
은 지금까지 운이 없었고 샘플에서 비슷한 것을 보지 못하지만 아이디어는 템플릿 공통 유스 케이스 .
해결책
이 문제가있었습니다.내가 한 일은 각 공통 블록 파일에 대해 정의한 다음 해당 파일이 모두 포함 된 패키지를 가져 오는 것입니다.
예 :
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>