0

I'm trying to embed JsonLd into my pages using Twirl, but for some reason the content gets HTMLentities-encoded.

My (twirl template) html looks like this:

@(jsonLd: String)(implicit config: play.api.Configuration)
@main() {
  <script type="application/ld+json">
    @jsonLd
  </script>
}

But when I look in the web browser I see something like: {&quot;@type&quot;:&quot;DataRecord&quot;,&quot;@context&quot;... etc.

How can I prevent @jsonLd from getting encoded??

1 Answer 1

1

By default, all dynamic contents is encoded for security reasons to avoid some common attacks (XSS). See here: https://www.playframework.com/documentation/2.8.x/ScalaTemplates#Escaping

You can use

@Html(jsonLd)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.