Reputation: 7288
I've created some utilities that help me at generating HTML and I reference them in my views as @div( "class" -> "well" ){ Hello Well. }
. Until now those classes were subclassing NodeSeq
because they aren't escaped then. But I need to get rid off the NodeSeq
in the top of my class hierarchy because Scala's xml is flawed and makes my code hacky and because I could switch to Traits then.
So I tried to find out how to prevent Play from escaping my Tag
-objects. But unfortunately the only valid solution that I found is to override the template compiler and have the user specify my compiler in his Build.scala
settings.
But I hopefully have overlooked a way more simple approach?
Upvotes: 4
Views: 1928
Reputation: 7288
Since version 2.2.0-M1
there appeared a new approach in the docs that explains how to add custom formats to the template engine. This allows me to easily integrate my utilities.
Custom Template Format: Java, Scala
Upvotes: 3
Reputation: 314
If your html helpers returns 'Html' rather than String you don't need to wrap them using the @Html tag in the view.
eg
import play.api.templates.Html
def a(src: String, value: String) : Html = Html(s"<a href='$src'>$value</a>")
Would be called in the view as below without needing to wrap in @Html
@a("www.example.com", "Example")
Upvotes: 3