def attrValue="whatever" //may be null
//test here
page.html {
body (onload:attrValue){
}
}
I assume I could do something like the following, but it seems too messy to
be a viable option:
page.html {
if(attrValue){
body (onload:attrValue){
} else {
body (){
}
}
}
Any help would be appreciated!
--
View this message in context: http://www.nabble.com/Conditional-attributes-in-MarkupBuilder--tp18403068p18403068.html
Sent from the groovy - user mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
page.omitNullAttributes = true
before you start using the builder.
Cheers, Paul.
J2R wrote:
> I really like the convenience of the markup builder for constructing HTML.
> I'm not sure, though, of the neatest way of adding attributes conditionally
> upon the outcome of a test. What I would like to do is simply to omit the
> attribute if some condition is met, but I don't know how to do that neatly.
> For example, in this code, I'd like to test the value of attrValue and if it
> is null, not have the onload attribute at all. Here, though, if it's null, I
> end up with <body onload=''> - i.e., an empty attribute rather than omitting
> it,
>
> def attrValue="whatever" //may be null
>
> //test here
> page.html {
>
> body (onload:attrValue){
> }
> }
>
> I assume I could do something like the following, but it seems too messy to
> be a viable option:
>
> page.html {
> if(attrValue){
> body (onload:attrValue){
> } else {
> body (){
> }
> }
> }
>
> Any help would be appreciated!
>
Paul King wrote:
>
>
> It looks like you are using MarkupBuilder (not the streaming kind).
> In which case, if want that behaviour globally, then you can do:
>
> page.omitNullAttributes = true
>
> before you start using the builder.
>
Thanks, yes, that will do the job.
--
View this message in context: http://www.nabble.com/Conditional-attributes-in-MarkupBuilder--tp18403068p18417774.html
Sent from the groovy - user mailing list archive at Nabble.com.