javascriptjsongrailsmeta-tags

Grails - How to render partial unescaped JSON inside a Meta tag in an HTML page


I'm passing a JSON String ({"myData":"data"}) to my rendered page like so:

render(view: 'myPage', model: [jsonData: JSONStr]);

then on the page template:

<meta content='http://www.myDomain.com/video?config=${ (jsonData) }' property="og:video" />

the result is:

<meta content='http://www.myDomain.com/video?config={&quot;myData&quot;:&quot;data&quot;}' property="og:video" />

Is There a way to prevent escaping of the JSON data?


Solution

  • I fixed it with a TagLib

    class SimpleTagLib {
    
     def unescaped = { attrs ->
          out << attrs.value  
      }
    
    }
    

    <meta content='http://www.myDomain.com/video?config=${g.noEncode(value:jsonData)}' property="og:video" />