Grails嵌套使用模板的taglibs?

时间:2015-01-15 17:55:20

标签: grails taglib

我想创建taglib来简化代表用户仪表板的网页。我想创建2个taglib。第一个是将在其他地方使用的通用面板,第二个是面板的更具体版本。

使用以下型号从控制器调用GSP:

def index() {
    def timelineItems = [
        [details: "Some text"],
        [details: "Some other text"]
    ]

    render(view: "index", model: [timelineItems: timelineItems])
}

我想要的GSP看起来像这样:

<dash:panel panelClass="col-lg-8" panelTitle="Service History">
    <p>Some text in the body here</p>
    <dash:timelinePanel timelineItems="$timelineItems" />
</dash:panel>

我想将HTML代码放在模板中以使编辑更简单,所以我从标签lib中调用render并传递数据模型。 taglibs看起来像这样(在名为dash的名称空间内):

def panel = {attrs, body ->
        out << render(template: "/dashboard/dashboardPanel", model:[panelClass: attrs.getAt("panelClass"), panelTitle: attrs.getAt("panelTitle"), body: body()])
    }

def timelinePanel = { attrs ->
        out << render(template: "/dashboard/dashboardTimelinePanel", model: [timelineItems: attrs.getAt("timelineItems")])
    }

这是我的通用面板模板:它应该在顶部div中呈现数据,然后简单地渲染在模型中传递给它的实体:

<div class="${panelClass}">
    <div class="panel panel-default">
        <div class="panel-heading">
            ${panelTitle}
        </div>
        <div class="panel-body">
            ${body}
        </div>
    </div>
</div>

这是我的时间轴模板:它应该呈现控制器在模型中传递的每个时间轴变量的详细信息。

<g:each in="${timelineItems}">
    <p>${it.details}</p>
</g:each>

我期待看到一个div,其中包括:

Some text in the body here
<p>Some text</p>
<p>Some other text</p>

但是,我收到以下错误:

Error evaluating expression [it.details] : No such property: details for class: java.lang.String

我的地图似乎正在转换为字符串,但我无法访问地图。我做错了什么?我想定义多个可以在彼此内部使用的标签。我该怎么做?

0 个答案:

没有答案
相关问题