0

我创建了一个 tmpl gsp 标记,其中包含一些标记,这些标记在我的 webapp (/shared/formRow.gsp) 中的整个表单中使用。我想在我创建的 groovy taglib 中引用这个 tmpl gsp 标签。这可能吗?

这是我的标签库中的def ...

def checkboxRow = { attrs ->
    def name = attrs.name
    def value = attrs.value
    def label = attrs.label
    def defaultLabel = attrs.defaultLabel

    out << "<tmpl:/shared/formRow name='${name}' label='${label}' defaultLabel='${defaultLabel}'>"
    out << "    ${checkBox(id: name, name: name, value: value)}"
    out << "</tmpl:/shared/formRow>"
}

我意识到 taglibs 中的语法有点不同(例如,您需要执行 ${checkBox(...)} 而不是 ),但是是否可以以类似的方式引用您自己的 tmpl gsp 标签?如果是这样,我会使用什么语法?

4

1 回答 1

0

好吧,事实证明它在 Grails 文档中,这里是。

你应该像这样调用渲染模板方法:

def formatBook = { attrs, body ->
    out << render(template: "bookTemplate", model: [book: attrs.book])
}

真的很简单!

于 2013-02-05T10:13:19.210 回答