2012-03-08 36 views
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 

還沒有任何運氣迄今爲止,我沒有看到樣品中類似的事情,但這個想法被覆蓋在Template common use cases

回答

1

我有這個問題。我所做的是爲每個公共塊定義一個文件,然後導入包含所有這些文件的包。

例如:

在views.common.component1.scala.html:

<div> 
    Common component 1 
</div> 

在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>