【问题标题】:Referencing <tmpl:myTemplate /> in grails taglib在 grails taglib 中引用 <tmpl:myTemplate />
【发布时间】:2013-02-02 11:20:46
【问题描述】:

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

这是我的 taglib 中的 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 标签?如果是这样,我会使用什么语法?

【问题讨论】:

    标签: grails groovy gsp taglib


    【解决方案1】:

    好吧,事实证明它在 Grails 文档中,here

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

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

    真的很简单!

    【讨论】:

      猜你喜欢
      • 2017-09-29
      • 1970-01-01
      • 1970-01-01
      • 2010-11-04
      • 1970-01-01
      • 1970-01-01
      • 2023-03-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多