-1

I am making a custom tag library in which I have to output html contents to the view using tag library. And we can output the contents like-

def globalCSS = { attrs, body ->
    out << '<!-- BEGIN GLOBAL MANDATORY STYLES -->'
    out << '<link href="http://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700&subset=all" rel="stylesheet" type="text/css">'
    out << '<link rel="stylesheet" type="text/css" href="'+g.resource(dir: 'assets/global/plugins/font-awesome/css', file: 'font-awesome.min.css', absolute: true)+'"/>'
    out << '<link rel="stylesheet" type="text/css" href="'+g.resource(dir: 'assets/global/plugins/simple-line-icons', file: 'simple-line-icons.min.css', absolute: true)+'"/>'
    out << '<link rel="stylesheet" type="text/css" href="'+g.resource(dir: 'assets/global/plugins/bootstrap/css', file: 'bootstrap.min.css', absolute: true)+'"/>'
    out << '<link rel="stylesheet" type="text/css" href="'+g.resource(dir: 'assets/global/plugins/uniform/css', file: 'uniform.default.css', absolute: true)+'"/>'
    out << '<!-- END GLOBAL MANDATORY STYLES -->'
}

Now the problem is that if I try to enter multiple lines in one out then it throws an error that-

def globalCSS = { attrs, body ->
    out << 'Bla bla bla
    Super bla bla
    Awesome bla bla'
}

Error-

Multiple markers at this line
- implements groovy.lang.Script.run
- Groovy:expecting ''', found '\r' @ line 10, 

So is there anyway to post multiple lines in one out? As it would be easy for me to copy paste the HTML code which I need to output so please suggest a way to do that.

Chetan
  • 1,707
  • 10
  • 17

1 Answers1

1

see http://groovy.codehaus.org/Strings+and+GString for the section Multiline Strings. Use ''' or """ to sourround multi line strings in groovy.

If you have a block of text which you wish to use but don't want to have to encode it all (e.g. if its a block of HTML or something) then you can use the """ syntax.

 def text = """\
 hello there ${name}
 how are you today?
 """

The trailing \ in the first line means, that the linebreak there should be ignored (for readability)

cfrick
  • 35,203
  • 6
  • 56
  • 68