2013-02-02 43 views
0

我創建了一個tmpl gsp標籤,其中包含一些標記,用於我的webapp(/shared/formRow.gsp)中的所有表單中。我想在我創建的groovy taglib中引用這個tmpl gsp標籤。這可能嗎?在grails中引用<tmpl:myTemplate /> taglib

下面是從我的taglib的高清...

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>" 
} 

我意識到語法是在標籤庫有點不同(例如,你需要做的$ {複選框(...)},而不是),但是否有可能以類似的方式引用你自己的tmpl gsp標籤?如果是這樣,我會用什麼語法?

回答

0

嗯,事實證明,它在Grails文檔中,here

你應該只調用render模板方法是這樣的:

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

其實很簡單!