Did you ever want to use builders in your grails taglib and wondered why the approach mentioned in the grails documentation doesn’t work at all? Here is what I found out after a lot of trial and error and digging in the MarkupBuilder, BuilderSupport and GroovyPagTagBody sources. Let’s stick with the example from the documentation and correct it until it works (the impatient can scroll down):

  1. def dialog = { attrs, body ->
  2.   def markup = new groovy.xml.MarkupBuilder(out)
  3.   markup {
  4.     div(‘class’: ‘dialog’) {
  5.       body()
  6. } } }

>> more…