Chapter 8. Producing output with view templates
This chapter covers
- An introduction to Scala templates
- The Scala template syntax
- Reusing template code and components
- Performing common tasks
We’ve seen how to structure and store data and business logs using models, and how to use controllers to bridge the gap between the Java world and the HTTP-based web.
We’ve covered the M and the C in MVC, but what about the V, the view layer? We need a view layer to present all the work our application does to the client, whether that is a browser or another system using our API.
When developing an application with Play, one of the options for creating output is using templates. You’ve probably used a templating system of some kind before, but you’ll find that the Scala template engine, the default template engine that comes with Play, is a little different. As we’ve demonstrated in earlier chapters, Scala templates are compiled into classes and are completely type-safe.
In this chapter we’ll show you everything you need to know to use Scala templates in your Play application to create your views. But Scala templates are not your only option. At the end of the chapter, we’ll show you some alternative template engines.
But first, we’ll dive deeper into how Scala templates work, and why they’re the default option, even for Java applications.