Reputation: 442
Is it possible in grails 3 to create a taglib using createLink and HTMLBuilder. I tried with :
def buttonTaglib = { attrs, body ->
def mb = new groovy.xml.MarkupBuilder(out)
mb.button(type: "button", class: "btn btn-success") {
g.createLink(controller: 'test', action: 'show', id: 1) { mkp.yield "buttonTaglib" }
}
}
and
def buttonTaglib2 = { attrs, body ->
def mb = new groovy.xml.MarkupBuilder(out)
out << g.createLink(controller:"test", action:"show") << mb.button(type: "button", class: "btn btn-success") { "buttonSimple" }
}
without success.
Upvotes: 0
Views: 280
Reputation: 442
This one is working for me:
def button = { attrs, body ->
def mb = new groovy.xml.MarkupBuilder(out)
out << link(controller: attrs.controller, action: attrs.action, id: attrs.id, params: attrs.params ) {
mb.button(type: attrs.type, class: attrs.class) {
mkp.yield attrs.name
}
}
}
Upvotes: 0
Reputation: 8587
Would your typical out used by standard suffice, if so it's as easy as this:
def buttonTaglib2 = { attrs, body ->
out << """
<a href="${g.createLink(controller:"test", action:"show")}" class="btn btn-success">Test</a>
"""
}
You can also just render a template and pass params or attrs to the tempalate. Then process your values as you would normally from controller to view.
Upvotes: 1