This first section will concentrate on what a template is, its structure, and its features. We'll see how it can help us to easily create views in a composable and sharable fashion.
A template in Play! Framework 2 is basically a file with a specific extension that commonly resides under the views
package. So, a template filename always has the following pattern:
<template-name>.scala.<content-type>
It is composed of the following:
A template name, which must be formatted like a variable (for example,
listContainer
). This will be used to reference it in the controllers.A first extension part,
.scala
, which is always the same. As stated earlier, templates are Scala-based.A second extension part, which is the real type of the data. Out of the box types are
.html
,.xml
, and.txt
, but Play! 2 is extensible enough to enable us to add new ones.
Play! 2 will detect these files based on the pattern and will compile them into functions...