0

I am trying to bold certain phrases in a Play template output, but all it does is output the HTML tag:

@signs.map {sign =>
            <tr>
            <td>@sign(2).replaceAll(phrase, "<b>" + phrase + "</b>") <strong>(@sign(0) : @sign(1) - @sign(3))</strong> </td>
            </tr>
            }

1 Answer 1

2

From https://www.playframework.com/documentation/2.5.x/ScalaTemplates#Escaping:

Escaping

By default, dynamic content parts are escaped according to the template type’s (e.g. HTML or XML) rules. If you want to output a raw content fragment, wrap it in the template content type.

For example to output raw HTML:

<p>
  @Html(article.content)
</p>
Sign up to request clarification or add additional context in comments.

4 Comments

Not following how this relates to the issue I am running into. Can you please explain.
sign(2).replaceAll(phrase, "<b>" + phrase + "</b>") is a string containing HTML. Twirl (the Play template engine) escapes HTML by default. Wrap it in @Html(...) to write the raw string into the view.
still not following. can you please give an example?
@Html(sign(2).replaceAll(phrase, "<b>" + phrase + "</b>"))

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.