Grails自定义标签库出多行
Grails custom tag library out multiple lines
我正在制作一个自定义标签库,我必须在其中使用标签库将 html 内容输出到视图。我们可以输出类似-
的内容
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 -->'
}
现在的问题是,如果我尝试在一行中输入多行 out
然后它会抛出一个错误 -
def globalCSS = { attrs, body ->
out << 'Bla bla bla
Super bla bla
Awesome bla bla'
}
错误-
Multiple markers at this line
- implements groovy.lang.Script.run
- Groovy:expecting ''', found '\r' @ line 10,
那么有没有办法 post 多行进一出呢?因为我很容易复制粘贴我需要输出的 HTML 代码,所以请建议一种方法。
请参阅 http://groovy.codehaus.org/Strings+and+GString 部分 Multiline Strings
。使用 '''
或 """
包围 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?
"""
第一行尾部的 \
意味着应该忽略那里的换行符(为了便于阅读)
我正在制作一个自定义标签库,我必须在其中使用标签库将 html 内容输出到视图。我们可以输出类似-
的内容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 -->'
}
现在的问题是,如果我尝试在一行中输入多行 out
然后它会抛出一个错误 -
def globalCSS = { attrs, body ->
out << 'Bla bla bla
Super bla bla
Awesome bla bla'
}
错误-
Multiple markers at this line
- implements groovy.lang.Script.run
- Groovy:expecting ''', found '\r' @ line 10,
那么有没有办法 post 多行进一出呢?因为我很容易复制粘贴我需要输出的 HTML 代码,所以请建议一种方法。
请参阅 http://groovy.codehaus.org/Strings+and+GString 部分 Multiline Strings
。使用 '''
或 """
包围 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? """
第一行尾部的 \
意味着应该忽略那里的换行符(为了便于阅读)