Special characters when using <g:set> tag

130 views
Skip to first unread message

Brian Lawson

unread,
Feb 18, 2015, 9:44:07 AM2/18/15
to grails-de...@googlegroups.com
I'm trying to use the following to set a variable in my gsp file, but am getting an error:

Code:
<
g:set var="createReqInd" value="<span class='required-indicator'>*</span>"/>

Error:
Attribute value quote wasn't closed (var="createReqInd" value="<span class='required-indicator').


Can someone please tell me how to set the variable to this string?

Thanks

Mikael Andersson

unread,
Feb 18, 2015, 5:50:53 PM2/18/15
to grails-de...@googlegroups.com
I think you can do something like this
<g:set var="createReqInd" value="${'<span class=\'required-indicator\'>*</span>'}"/>




--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grails-dev-disc...@googlegroups.com.
To post to this group, send email to grails-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/e0d9e0fe-e5d1-4586-94c2-e8ccea89d761%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mikael Andersson

unread,
Feb 19, 2015, 3:57:09 AM2/19/15
to grails-de...@googlegroups.com
Almost feel negligent for not making sure you were aware of how easy it is to create and custom tags in Grails, something which is perfect for when you want to re-use snippets of gsp/html.

class MyTagLib{
def requiredIndicator = {attrs ->
String indicator = attrs.indicator ?: '*'
out << "<span class='required-indicator'>${indicator}</span>"
}
}

This lives in grails-app/taglib folder under a package of your choosing.

And can then be easily used like this in your GSPs

<g:requiredIndicator />
or
<g:requiredIndicator indicator="req" />

There is lots more to custom tags (use of services, templates, body, etc.)

Hope this helps
Micke

Brian Lawson

unread,
Feb 19, 2015, 11:28:36 AM2/19/15
to grails-de...@googlegroups.com
Thanks Mikael,

I am very new to Groovy and Grails and I did not know about the custom tags.  Great to know!

Brian Lawson

unread,
Feb 19, 2015, 11:32:40 AM2/19/15
to grails-de...@googlegroups.com
I tried this just as a simple "get it working" bandaid, but I'm getting the same error.


On Wednesday, February 18, 2015 at 4:50:53 PM UTC-6, Mikael Andersson wrote:
I think you can do something like this
<g:set var="createReqInd" value="${'<span class=\'required-indicator\'>*</span>'}"/>



On 18 February 2015 at 14:44, Brian Lawson <brianle...@gmail.com> wrote:
I'm trying to use the following to set a variable in my gsp file, but am getting an error:

Code:
<
g:set var="createReqInd" value="<span class='required-indicator'>*</span>"/>

Error:
Attribute value quote wasn't closed (var="createReqInd" value="<span class='required-indicator').


Can someone please tell me how to set the variable to this string?

Thanks

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grails-dev-discuss+unsub...@googlegroups.com.

Mikael Andersson

unread,
Feb 19, 2015, 4:16:14 PM2/19/15
to grails-de...@googlegroups.com
Interesting, I tried that myself in an app I have which use Grails 2.2.4 and it worked.

To unsubscribe from this group and stop receiving emails from it, send an email to grails-dev-disc...@googlegroups.com.

To post to this group, send email to grails-de...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages