2013-03-26 61 views
0

是否有Grails的GSP的方式來替換以下帶有內容的Grails GSP外部模板?

<tmpl:/templates/header /> 
<!-- tmpl namespace call is equivalent to <g:render template="/templates/header" /> -->  

<!-- definition of inner content --> 

<tmpl:/templates/footer /> 

與外部模板?從本質上講,這是一種進口的包裝外模板,

<outertemplate:templatename> 
<!-- header will be rendered from outer template --> 

<!-- definition of inner content --> 

<!-- footer will be rendered from outer template --> 
</outertemplate:templatename> 

和外模板被一些沿着

<!-- definition of header content --> 

<!-- placeholder or attr for inner content --> 

<!-- definition of footer content --> 

封裝在一個模板與兩個包裹內容系定義。 IIRC在JSF下有辦法做到這一點,但我無法在GSP下找到相應的等價物。

+1

我不確定你在問什麼。模板可以呈現模板。 – 2013-03-26 21:29:59

+0

你能詳細解釋一下你的問題嗎? – 2013-03-26 21:32:14

+0

@詹姆斯麥克馬洪,你的問題太明確,你試圖做的明顯重構。我們需要知道tmpl tagLib先做了什麼。 – rimero 2013-03-26 22:11:53

回答

1

確定,所以我正在尋找的是Grails' SiteMesh layout support,允許我以更口才方式限定常用視圖標記然後模板。

所以頁眉和頁腳的內容可以在一個佈局

<html> 
    <head> 
     <title><g:layoutTitle/></title> 
     <g:layoutHead /> 
    </head> 
    <body> 
     <!-- HEADER CONTENT DEFINED HERE (or for stuff in head in the head above --> 
     <g:layoutBody /> 
     <!-- FOOTER CONTENT DEFINED HERE --> 
    </body> 
</html> 

內,然後使用的佈局,

<html> 
    <head> 
     <title>An Example Page</title> 
     <meta name="layout" content="main" /> 
    </head> 
    <body>This is my content!</body> 
</html> 

我認爲這是更清潔,然後頁眉和頁腳模板。

You can also nest layouts.

1

您可以創建這樣的使用標籤庫。

class SimpleTagLib { 
    def emoticon = { attrs, body -> 
     out << body() << (attrs.happy == 'true' ? " :-)" : " :-(") 
    } 
} 

此定義可以在GSP可以使用這樣的標籤emoticon

<g:emoticon happy="true">Hi John</g:emoticon> 

body()用於呈現所述標籤體的內容。

(這個例子是從官方grails documentation複製)

+0

啊我支持我可以做一個標籤庫來渲染其他模板,並通過在內部的內容,似乎有點重,但我還是搞清楚這一切的Grails/GSP的東西 – 2013-03-29 14:21:19