0

I want to embed JSON in the DOM as outlined in the below question:

Best practice for embedding arbitrary JSON in the DOM?

However I can't figure out how to do this with Scalate/Scalatra. I have this in my scaml template:

-@ val fullStateJson: String

and I can render it via

%div= fullStateJson

but I can't figure out how to get this into a <script>. When I do

%script(type="application/json" id="fullStateScript") =fullStateJson

It ends up escaped, like

{&quot;45&quot;:{&quot;id&quot;:45,&quot;level&quot;:0},&quot;98&quot;:{&quot;id&quot;:98,&quot;level&quot;:0}}
4

1 回答 1

1

TemplateEngine.escapeMarkup默认情况下设置为 true,因此它会更改 html 特殊字符。

你可以把它放在你的模板中:<% escapeMarkup = false %>

于 2016-10-31T19:26:47.253 回答