$ dollar sign character and jQuery error

1,419 views
Skip to first unread message

Seymores

unread,
Jan 5, 2010, 10:43:25 AM1/5/10
to Gaelyk
I was surprise to get this error when I tried to use jquery script in
*.gtpl page. The error I got is:

groovy.lang.GroovyRuntimeException: Failed to parse template script
(your template may contain an error or be trying to use expressions
not currently supported): startup failed:
SimpleTemplateScript10.groovy: 16: illegal string body character after
dollar sign;
solution: either escape a literal dollar sign "\$5" or bracket the
value expression "${5}" @ line 16, column 10.
out.print(" $(\"#test\");\n");


Am I missing something or the SimpleTemplateScript need to be changed/
configure to ignore $() ?


Sey

Guillaume Laforge

unread,
Jan 5, 2010, 2:01:14 PM1/5/10
to gae...@googlegroups.com
Hi Sey,

Actually, the error message is quite good and explicit, no?
You just need to escape the $ with a backslash \.
Because $ is used for GStrings in Groovy, and hence in templates too.
So just do \$.ajax... etc.

Guillaume

PS: For instance, the Groovy Web Console is using jQuery. And I had to escape the $. There's also the possibility of using the 'jquery' syntax instead of the dollar sign.

2010/1/5 Seymores <seym...@gmail.com>
--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes Gaelyk.
Pour envoyer un message à ce groupe, adressez un e-mail à gae...@googlegroups.com.
Pour vous désabonner de ce groupe, envoyez un e-mail à l'adresse gaelyk+un...@googlegroups.com.
Pour plus d'options, consultez la page de ce groupe : http://groups.google.com/group/gaelyk?hl=fr






--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one

Seymores

unread,
Jan 5, 2010, 6:16:00 PM1/5/10
to Gaelyk
Yes, the message is clear here. It works well for Grails to only use $
{} and jquery $() continue to works as expected so I'm merely
surprised that this is a limitation for gaelyk.

Thanks!

sey

On Jan 6, 3:01 am, Guillaume Laforge <glafo...@gmail.com> wrote:
> Hi Sey,
>
> Actually, the error message is quite good and explicit, no?
> You just need to escape the $ with a backslash \.
> Because $ is used for GStrings in Groovy, and hence in templates too.
> So just do \$.ajax... etc.
>
> Guillaume
>
> PS: For instance, the Groovy Web Console is using jQuery. And I had to
> escape the $. There's also the possibility of using the 'jquery' syntax
> instead of the dollar sign.
>

> 2010/1/5 Seymores <seymo...@gmail.com>


>
>
>
> > I was surprise to get this error when I tried to use jquery script in
> > *.gtpl page. The error I got is:
>
> > groovy.lang.GroovyRuntimeException: Failed to parse template script
> > (your template may contain an error or be trying to use expressions
> > not currently supported): startup failed:
> > SimpleTemplateScript10.groovy: 16: illegal string body character after
> > dollar sign;
> >   solution: either escape a literal dollar sign "\$5" or bracket the
> > value expression "${5}" @ line 16, column 10.
> >   out.print("            $(\"#test\");\n");
>
> > Am I missing something or the SimpleTemplateScript need to be changed/
> > configure to ignore $() ?
>
> > Sey
>
> > --
> > Vous recevez ce message, car vous êtes abonné au groupe Google
> > Groupes Gaelyk.
> > Pour envoyer un message à ce groupe, adressez un e-mail à
> > gae...@googlegroups.com.
> > Pour vous désabonner de ce groupe, envoyez un e-mail à l'adresse

> > gaelyk+un...@googlegroups.com<gaelyk%2Bunsu...@googlegroups.com>

Seymores

unread,
Jan 5, 2010, 8:34:54 PM1/5/10
to Gaelyk
Haha, Gaelyk is not Grails, need to have to remind myself.

huydung

unread,
Jan 5, 2010, 9:09:15 PM1/5/10
to Gaelyk
Why don't you write your javascript in a separated .js file anyway?

Seymores

unread,
Jan 6, 2010, 8:07:03 PM1/6/10
to Gaelyk
That's a good reminder. Thanks!

Lucas F. A. Teixeira

unread,
Jan 7, 2010, 6:20:29 AM1/7/10
to gae...@googlegroups.com
sometimes you'll have to write some scripts in the page, sometimes will happen.
the best practice for sure, is use jQuery(xxx)

[]s,
Pour vous désabonner de ce groupe, envoyez un e-mail à l'adresse gaelyk+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages