Grails GSP具有内部内容的外部模板?
Grails GSP中有没有替代以下内容的方法Grails GSP具有内部内容的外部模板?,grails,grails-2.0,gsp,Grails,Grails 2.0,Gsp,Grails GSP中有没有替代以下内容的方法 <tmpl:/templates/header /> <!-- tmpl namespace call is equivalent to <g:render template="/templates/header" /> --> <!-- definition of inner content --> <tmpl:/templates/footer /> 使用外部模板?本
<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下找不到类似的方法。您可以使用标记库创建类似的内容
class SimpleTagLib {
def emoticon = { attrs, body ->
out << body() << (attrs.happy == 'true' ? " :-)" : " :-(")
}
}
body()
用于呈现标记正文内容
(这个例子是从官方网站上复制的)好的,所以我要找的是,它允许我以比模板更雄辩的方式定义常用的视图标记 因此,页眉和页脚内容可以放置在布局中
<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>
示例页
这是我的内容!
我认为这比页眉和页脚模板要干净得多
我不知道你在问什么。模板可以呈现模板。你能详细说明你的问题吗?@James McMahon,你的问题对于你试图进行的表面重构来说太具体了。我们需要知道tmpl标记库首先做了什么。我已经尝试让问题更清楚,抱歉混淆。啊,我支持我可以制作一个标记库来呈现另一个模板并传递内部内容,看起来有点沉重,但我仍然在弄清楚所有这些grails/gsp的东西
<html>
<head>
<title>An Example Page</title>
<meta name="layout" content="main" />
</head>
<body>This is my content!</body>
</html>