How to load and display templates in Play! 2.0?

In the old game! Downloading the v1 template was very easy. But now I don't understand how I can use Scala templates in a similar manner to the method below:

val template = TemplateLoader.load(templateName)
val body = template.render(templateBinding)

      

The above example uses a rendered template to be used for 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? Thank!

+3


source to share


1 answer


Templates are now compiled by java classes. you don't need to "download" them.

It looks like you are trying to make a tag. In this 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 using html.Mails.emailtemplate(tags)

and using the method render()

to create the template. If you only want the text or body of the template, you can also use the type syntax html.Mails.emailtemplate(tags).body

.

In this mailer class for Play, you can see a specific use case related to this question! in the Gist: https://gist.github.com/2210788

+6


source







All Articles