q99
q99

Reputation: 1011

Escape html in template PlayFramework

I'd like to escape a HTML in my template, but no matter what I try it won't work

Here is my template:

<ul>
    @for(index <- 0 until appointments.size){
    <li>
        @(utils.DateUtil.getLocalDate(appointments(index).getStartDate())) - @appointments(index).getReason()
<ul>

@{val procedure = appointments(index).getProcedures()

    {if(procedure == null){
    <b>Empty</b>
} else {
    "&gt;b/&lt;NotEmpty&gt;/b&lt;" +
    procedure.size().toString+
    procedure.size().toString+
        <b>NotEmpty</b>+
    "<b>NotEmpty</b>"+
    "<b>NotEmpty</b>".toString;
}
}


            }


        </ul>

    </li>
    }

</ul>

The problematic code is in the else branch

I'm trying to print <b>NotEmpty</b> as NotEmpty but I've got just a plaintext, not html

I've tried @Html("<strong>Do not escape</strong>") but it says expected start of definition

if I delete the else branch contents and leave just

else {
    <b>NotEmpty</b>;
}

It prints out fine. I'm using play framework 2.2.1 built with Scala 2.10.2 (running Java 1.7.0_25)

Upvotes: 1

Views: 955

Answers (1)

ed.
ed.

Reputation: 2706

How about:

@{
  val x = Some(Seq("hi there")) 

  if(x.isDefined)
    <b>size = {x.get.size}</b><br/>
    <b>Not Empty</b>
  else
    <b>Empty</b>
}

Upvotes: 1

Related Questions