Reputation: 13300
In the old Play! v1 template loading was very simple. But now I'm at a loss to figure out how I can use Scala templates in a similar fashion to the method below:
val template = TemplateLoader.load(templateName)
val body = template.render(templateBinding)
The use case above is rendering a template to be used for an email in Scala.
The new Scala API has a similar class for working with templates http://www.playframework.org/documentation/api/2.0/scala/index.html#play.api.templates.Html but how would you load the template? Should I just bite the bullet and import Groovy templates? Thanks!
Upvotes: 3
Views: 2509
Reputation: 51435
Templates are now compiled java classes. you don't really need to "load" them.
Looks like what you are trying to do is a tag. In which case I would recommend reading this page: http://www.playframework.org/documentation/2.0/ScalaTemplates
Each template is a function and can be easily called with html.Mails.emailtemplate(tags)
and use the render()
method to build the template. If you only need the text or body of the template, you can also use a syntax like html.Mails.emailtemplate(tags).body
.
A particular use case related to the question can be seen in this mailer class for Play! in Gist: https://gist.github.com/2210788
Upvotes: 6