I have some view (“basicView.gsp”) and want to pass other view content (“_someTemplate.gsp”) to this view to javascript variable (“template”).

basicView.gsp:

<html>
<head>
...
</head>
<body>
...
<script>
var template = '${raw(include(view:"myTemplates/_someTemplate.gsp").replaceAll('\n',''))}';
</script>
</body>
</html>

_someTemplate.gsp:

<div>
<h1>Some header</h1>
<p>Lorem ipsum dolor sit...</p>
</div>

Resulted html:

<html>
<head>
...
</head>
<body>
...
<script>
var template = '<div><h1>Some header</h1><p>Lorem ipsum dolor sit...</p></div>';
</script>
</body>
</html>

Leave a reply

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> 

required