Last Updated: February 25, 2016
· ydeshayes

Generate file with Play! framework template system

In this article I will show you how to generate files with the play built-in template system.

When we write templates in scala for Play! we use the "someName.scala.html" format. Then play generate the html package with the class someName in it.

This system allow us to use "someName.scala.txt" and "someName.scala.xml" format, they work the same way, so Play! will create a txt or xml package with your class in it.

If we want to create a template for a txt file for example:

  • Create a someName.scala.txt file where you want

  • In your class import yourPackage.txt.someName;

  • In your function call render like this: String content = someName.render(yourArgs, ...).toString();

  • Write it on a file with the built-in function: writeFile(path: File, content: String)

Say Thanks