2011-11-24 14 views
2

從一個主html模板我打電話#{doLayout}呈現我的看法html。我想調用一個自定義html模板,例如#{happyHeader},我想在我的視圖html文件中定義它。事情是這樣的:如何在PlayFramework視圖內定義一個html子模板?

<html> 
    <body> 
    #{happyHeader} 
    <hr/> 
    #{doLayout} 
    </body> 
</html> 

在我index.html有這樣的事情:

<p>My happy doLayout main content here</p> 
#{define happyHeader} 
    <h1>Nice header</h1> 
#{/} 

我看了看周圍的StackOverflow,但沒有找到一個類似的問題,也不做自定義模板解決方案Play Framework文檔似乎涵蓋了這一點。

回答

4

你可以用#{set}#{get}來做到這一點。

你在你的index.html設置的值是這樣的:

#{set 'happyHeader'} 
    <h1>Nice header</h1> 
#{/set} 

,你會得到它在你的main.html這樣的:

#{get 'happyHeader' /} 
相關問題