简体   繁体   中英

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?

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" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM