0

I'm working on a project in Play (+Scala) where after a particular flow, an email is sent.

The email uses a template (e.g. email.scala.html), which contains HTML and inserts data from a "model" (which is really a Map[String, String])

What I find is some text is encoded which I don't want encoded

For example:

<a href="http://madeupsite.com?param1=x&param2=y">link</a>

Gets encoded like (notice & gets replaced with &amp;):

<a href="http://madeupsite.com?param1=x&amp;param2=y">link</a>

This will break the link that gets emailed

How this gets included in the template:

<a href="@emailModel.get("url").get">link</a>

In code:

def prepareEmail(tuple: (Map[String, String], Map[String, String])): HtmlEmail = tuple match {

          case (headers, emailBody) if headers.nonEmpty && emailBody.nonEmpty => {
            def createMessageFromTemplate(model: Map[String, String]): String = {
              views.html.email(model).toString
            }
...

This line is the important bit

views.html.email(model).toString

I can't seem to find anything on rendering this without encoding

For example these don't seem to work:

@Html(...)
@TxtFormat.raw(...)
@TxtFormat.raw(...).toString.replace("&amp;", "&")

I'm not a Play/Scala expert, so any help would be much appreciated

claritee
  • 61
  • 5
  • What is the value of `emailModel.get("url").get`? Is it already escaped? – Michael Zajac Dec 01 '16 at 14:40
  • 1
    Probably `&` should be encoded to `&` within `href=""`. For sure it is the case for `xhtml`;) http://stackoverflow.com/questions/3705591/do-i-encode-ampersands-in-a-href . w3 validator has been complaining about unencoded ampersands within attributes. – michaJlS Dec 01 '16 at 21:03

0 Answers0