Nile
Nile

Reputation: 396

How to build html using Groovy MarkupBuilder?

I try a simple groovy script.

def builder = new groovy.xml.MarkupBuilder(out)
builder.ul{
     li {
        a( href : "href.html" ) { 
           span(class:"class") 
           "Content" 
           }
     }
 }

output:

<ul>
  <li>
    <a href='href.html'>
        <span class='class' />
    </a>
  </li>
</ul>

my Question is why "Content" is missing? How could i fix this.

Groovy version 1.7.10

EDIT:

what i wanted is ("Content" outside <span>)

<ul>
  <li>
    <a href='href.html'>
        <span class='class' />
        Content
    </a>
  </li>
</ul>

Upvotes: 1

Views: 6290

Answers (1)

dmahapatro
dmahapatro

Reputation: 50245

UPDATE:

With latest edit to question, answer should be:

builder.ul{
    li {
       a( href : "href.html" ) { 
           span class:"class"
           mkp.yield "Content"
       }
    }
}

Upvotes: 4

Related Questions