Nathan Reese
Nathan Reese

Reputation: 2734

In a grails GSP, how do you escape GString expressions

I need to write some javascript in a GSP that contains the character sequence ${} (OpenLayers Style - Attribute Replacement Syntax). Unfortunatly, this is also the syntax for a groovy gstring expression. How do I escape it so that Grails does not interpret the character sequence as a gstring. I have tried '\' but that did not work.

Upvotes: 4

Views: 3568

Answers (2)

Ian Roberts
Ian Roberts

Reputation: 122364

The way I usually do this is

${'${test}'}

or alternatively

${'$'}{test}

Note the use of single rather than double quotes - ${"${test}"} would not work because the inner ${} would be interpreted as a GString rather than a literal.

Upvotes: 5

Anuj Aneja
Anuj Aneja

Reputation: 1344

Try this:

alert("\$\{test\}");

Output:

${test}

Upvotes: 1

Related Questions