2013-03-26 52 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